diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-11-28 18:47:42 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-11-30 12:10:26 -0800 |
commit | c7f272e05e1cf8c7d7caefe5ee542845cf4cc7c8 (patch) | |
tree | 4e0c0ac7ef80f00d23e04e1b35c53052f80446af /gcc/go | |
parent | 8d8fea8a57068a0c5f0c1df766679a25f4272481 (diff) | |
download | gcc-c7f272e05e1cf8c7d7caefe5ee542845cf4cc7c8.zip gcc-c7f272e05e1cf8c7d7caefe5ee542845cf4cc7c8.tar.gz gcc-c7f272e05e1cf8c7d7caefe5ee542845cf4cc7c8.tar.bz2 |
compiler: use correct assignment order for type assertions
For "a, b := v.(T)" we must set a before b.
For golang/go#13433
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/273906
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/MERGE | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/statements.cc | 28 |
2 files changed, 27 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 698969f..e2fc0b5 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -af683486b4de5503b2b6d9ae974a2ab1eeb92290 +213abeedc85ed638a878f9457e422897fda3a111 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/statements.cc b/gcc/go/gofrontend/statements.cc index ad89807..25e2536 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -1985,18 +1985,42 @@ Tuple_type_guard_assignment_statement::lower_to_object_type( NULL, loc); b->add_statement(val_temp); - // ok = CODE(type_descriptor, expr, &val_temp) + // var ok_temp bool + Temporary_statement* ok_temp = NULL; + if (!this->ok_->is_sink_expression()) + { + ok_temp = Statement::make_temporary(this->ok_->type(), + NULL, loc); + b->add_statement(ok_temp); + } + + // ok_temp = CODE(type_descriptor, expr, &val_temp) Expression* p1 = Expression::make_type_descriptor(this->type_, loc); Expression* ref = Expression::make_temporary_reference(val_temp, loc); Expression* p3 = Expression::make_unary(OPERATOR_AND, ref, loc); Expression* call = Runtime::make_call(code, loc, 3, p1, this->expr_, p3); - Statement* s = Statement::make_assignment(this->ok_, call, loc); + Statement* s; + if (ok_temp == NULL) + s = Statement::make_statement(call, true); + else + { + Expression* ok_ref = Expression::make_temporary_reference(ok_temp, loc); + s = Statement::make_assignment(ok_ref, call, loc); + } b->add_statement(s); // val = val_temp ref = Expression::make_temporary_reference(val_temp, loc); s = Statement::make_assignment(this->val_, ref, loc); b->add_statement(s); + + // ok = ok_temp + if (ok_temp != NULL) + { + ref = Expression::make_temporary_reference(ok_temp, loc); + s = Statement::make_assignment(this->ok_, ref, loc); + b->add_statement(s); + } } // Dump the AST representation for a tuple type guard statement. |