compiler: fix double evaluation with interface field expression
In Interface_field_reference_expression, the interface expression
is used in two places, so a temporary variable is used. Previously,
we used a Set_and_use_temporary_expression, which, when evaluated
twice, causes double evaluation of the underlying expression. Fix
by setting the temporary once and use Temporary_reference_expression
instead.
Fixes golang/go#26248.
Change-Id: Ieec464201a5498c3c8c4a1751c3bb79f4a2b515c
Reviewed-on: https://go-review.googlesource.com/122756
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/go/expressions.cc b/go/expressions.cc
index 75b8b69..89b265b 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -11886,10 +11886,9 @@
if (!this->expr_->is_variable())
{
Temporary_statement* temp =
- Statement::make_temporary(this->expr_->type(), NULL, this->location());
+ Statement::make_temporary(NULL, this->expr_, this->location());
inserter->insert(temp);
- this->expr_ = Expression::make_set_and_use_temporary(temp, this->expr_,
- this->location());
+ this->expr_ = Expression::make_temporary_reference(temp, this->location());
}
return this;
}