compiler: additional lvalue/rvalue context fixes
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 9 Jun 2017 04:35:57 +0000 (04:35 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 9 Jun 2017 04:35:57 +0000 (04:35 +0000)
    Fix lvalue/rvalue context mixup Set_and_use_temporary_expression's
    do_get_backend() method. Enhance Mark_lvalue_varexprs to handle
    conversions and temporary reference expressions, since occasionally
    the front end emits code such as "deref(conv(tempref)) = ...".

    Reviewed-on: https://go-review.googlesource.com/45141

From-SVN: r249047

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/statements.cc

index 3280bcfe1f88215e8227eb01148f485fb5b47d48..1bfac59adef5ed766ab0344ea441dfc9d029f79a 100644 (file)
@@ -1,4 +1,4 @@
-82961ce59e8bb02598d963d2a05b3acca860d9dd
+d4875b19266d5f726e0e32843b903075f5c50b4c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 5689c77c0d8dfe34dc27e1aa0691d5c8762b8ba8..d6d27eea8d34e6859fb800970ad4a313dd726619 100644 (file)
@@ -962,7 +962,7 @@ Set_and_use_temporary_expression::do_get_backend(Translate_context* context)
   Location loc = this->location();
   Gogo* gogo = context->gogo();
   Bvariable* bvar = this->statement_->get_backend_variable(context);
-  Bexpression* lvar_ref = gogo->backend()->var_expression(bvar, VE_rvalue, loc);
+  Bexpression* lvar_ref = gogo->backend()->var_expression(bvar, VE_lvalue, loc);
 
   Named_object* fn = context->function();
   go_assert(fn != NULL);
@@ -970,7 +970,7 @@ Set_and_use_temporary_expression::do_get_backend(Translate_context* context)
   Bexpression* bexpr = this->expr_->get_backend(context);
   Bstatement* set = gogo->backend()->assignment_statement(bfn, lvar_ref,
                                                           bexpr, loc);
-  Bexpression* var_ref = gogo->backend()->var_expression(bvar, VE_lvalue, loc);
+  Bexpression* var_ref = gogo->backend()->var_expression(bvar, VE_rvalue, loc);
   Bexpression* ret = gogo->backend()->compound_expression(set, var_ref, loc);
   return ret;
 }
index ae3873ed189aae4e923bc04e5fabb4121e4c43f2..7a448d7a60601cbde8c35835cc4634fc546104d6 100644 (file)
@@ -912,6 +912,21 @@ int Mark_lvalue_varexprs::expression(Expression** ppexpr)
   if (ue && ue->op() == OPERATOR_MULT)
     return TRAVERSE_CONTINUE;
 
+  Type_conversion_expression* ce = e->conversion_expression();
+  if (ce)
+    return TRAVERSE_CONTINUE;
+
+  Temporary_reference_expression* tre =
+      e->temporary_reference_expression();
+  if (tre)
+    {
+      tre = new Temporary_reference_expression(tre->statement(),
+                                               tre->location());
+      *ppexpr = tre;
+      tre->set_is_lvalue();
+      return TRAVERSE_EXIT;
+    }
+
   return TRAVERSE_EXIT;
 }