compiler: additional lvalue/rvalue context fixes

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
This commit is contained in:
Ian Lance Taylor 2017-06-09 04:35:57 +00:00
parent 120ef1d50a
commit 1ee77fbdea
3 changed files with 18 additions and 3 deletions

View File

@ -1,4 +1,4 @@
82961ce59e8bb02598d963d2a05b3acca860d9dd d4875b19266d5f726e0e32843b903075f5c50b4c
The first line of this file holds the git revision number of the last The first line of this file holds the git revision number of the last
merge done from the gofrontend repository. merge done from the gofrontend repository.

View File

@ -962,7 +962,7 @@ Set_and_use_temporary_expression::do_get_backend(Translate_context* context)
Location loc = this->location(); Location loc = this->location();
Gogo* gogo = context->gogo(); Gogo* gogo = context->gogo();
Bvariable* bvar = this->statement_->get_backend_variable(context); 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(); Named_object* fn = context->function();
go_assert(fn != NULL); 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); Bexpression* bexpr = this->expr_->get_backend(context);
Bstatement* set = gogo->backend()->assignment_statement(bfn, lvar_ref, Bstatement* set = gogo->backend()->assignment_statement(bfn, lvar_ref,
bexpr, loc); 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); Bexpression* ret = gogo->backend()->compound_expression(set, var_ref, loc);
return ret; return ret;
} }

View File

@ -912,6 +912,21 @@ int Mark_lvalue_varexprs::expression(Expression** ppexpr)
if (ue && ue->op() == OPERATOR_MULT) if (ue && ue->op() == OPERATOR_MULT)
return TRAVERSE_CONTINUE; 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; return TRAVERSE_EXIT;
} }