diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-12 17:51:52 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-12 17:51:52 +0000 |
commit | 20d5c8731f4bc1aa72ced6cf61016407b74109d5 (patch) | |
tree | 65218f1f3dbd2484a4cafa7fafda0b3ed2155fb7 | |
parent | 754d67d5ba4a1f9994210d402893a4cf49ce6a71 (diff) | |
download | gcc-20d5c8731f4bc1aa72ced6cf61016407b74109d5.tar.gz |
compiler: avoid orphaning Bexpressions when processing conversions
The method Type_conversion_expression::do_get_backend was (in some
circumstances) creating a Bexpression for the source expression of the
conversion and then throwing it away before using it. Fix up this
method to insure that the call to get_backend() on the source
expression is only made when the result will be used.
Reviewed-on: https://go-review.googlesource.com/45350
From-SVN: r249131
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 12 |
2 files changed, 10 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 1bfac59adef..aebab77b1d3 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -d4875b19266d5f726e0e32843b903075f5c50b4c +61222d34c1b33a369bd86008a0541455dd17727e 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 d6d27eea8d3..5eec731733f 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -3410,11 +3410,13 @@ Type_conversion_expression::do_get_backend(Translate_context* context) Gogo* gogo = context->gogo(); Btype* btype = type->get_backend(gogo); - Bexpression* bexpr = this->expr_->get_backend(context); Location loc = this->location(); if (Type::are_identical(type, expr_type, false, NULL)) - return gogo->backend()->convert_expression(btype, bexpr, loc); + { + Bexpression* bexpr = this->expr_->get_backend(context); + return gogo->backend()->convert_expression(btype, bexpr, loc); + } else if (type->interface_type() != NULL || expr_type->interface_type() != NULL) { @@ -3483,6 +3485,7 @@ Type_conversion_expression::do_get_backend(Translate_context* context) else if (type->is_numeric_type()) { go_assert(Type::are_convertible(type, expr_type, NULL)); + Bexpression* bexpr = this->expr_->get_backend(context); return gogo->backend()->convert_expression(btype, bexpr, loc); } else if ((type->is_unsafe_pointer_type() @@ -3493,7 +3496,10 @@ Type_conversion_expression::do_get_backend(Translate_context* context) || (this->may_convert_function_types_ && type->function_type() != NULL && expr_type->function_type() != NULL)) - return gogo->backend()->convert_expression(btype, bexpr, loc); + { + Bexpression* bexpr = this->expr_->get_backend(context); + return gogo->backend()->convert_expression(btype, bexpr, loc); + } else { Expression* conversion = |