aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-08-03 18:23:39 -0700
committerIan Lance Taylor <iant@golang.org>2020-08-04 10:21:37 -0700
commitacf83db025cfd4a67724838e9dbd19813f4f5960 (patch)
tree12cde63bf9a622dfefb2888799f6c411a960f8ae
parent1790d13dc8ffb3b454f2ca5e4a6d6d482f7fa985 (diff)
downloadgcc-acf83db025cfd4a67724838e9dbd19813f4f5960.zip
gcc-acf83db025cfd4a67724838e9dbd19813f4f5960.tar.gz
gcc-acf83db025cfd4a67724838e9dbd19813f4f5960.tar.bz2
compiler: delete lowered constant strings
If we lower a constant string operation in a Binary_expression, delete the strings. This is safe because constant strings are always newly allocated. This is a hack to use much less memory when compiling the new time/tzdata package, which has a file that contains the sum of over 13,000 constant strings. We don't do this for numeric expressions because that could cause us to delete an Iota_expression. We should have a cleaner approach to memory usage some day. Fixes PR go/96450
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/expressions.cc9
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 0bc8e1b..c21b600 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-7f0d3834ac40cf3bcbeb9b13926ab5ccb2523537
+f45afedf90ac9af8f03d7d4515e952cbd724953a
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 90f860b..7e7fb8c 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -556,7 +556,10 @@ Expression::get_backend(Translate_context* context)
{
// The child may have marked this expression as having an error.
if (this->classification_ == EXPRESSION_ERROR)
- return context->backend()->error_expression();
+ {
+ go_assert(saw_errors());
+ return context->backend()->error_expression();
+ }
return this->do_get_backend(context);
}
@@ -6080,6 +6083,8 @@ Binary_expression::do_lower(Gogo* gogo, Named_object*,
Type* result_type = (left->type()->named_type() != NULL
? left->type()
: right->type());
+ delete left;
+ delete right;
return Expression::make_string_typed(left_string + right_string,
result_type, location);
}
@@ -6087,6 +6092,8 @@ Binary_expression::do_lower(Gogo* gogo, Named_object*,
{
int cmp = left_string.compare(right_string);
bool r = Binary_expression::cmp_to_bool(op, cmp);
+ delete left;
+ delete right;
return Expression::make_boolean(r, location);
}
}