aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-06-23 17:11:05 -0700
committerIan Lance Taylor <iant@golang.org>2022-06-24 11:24:57 -0700
commitbb403de36aa29e5398119e78a2c96794bdd6bad8 (patch)
tree3c1d19ed12841958ec7a834e3e2ff5a51c096843 /gcc/go
parentbb8e93eb1acae30a5fbe7e13149493ce4ccd301a (diff)
downloadgcc-bb403de36aa29e5398119e78a2c96794bdd6bad8.zip
gcc-bb403de36aa29e5398119e78a2c96794bdd6bad8.tar.gz
gcc-bb403de36aa29e5398119e78a2c96794bdd6bad8.tar.bz2
compiler: use bool for comma-ok if not already boolean
If a comma-ok variable already has a type, and that type is not a boolean type, then set the type of the temporary variable to bool. Otherwise we may try to convert an unnamed bool type to an interface type, which will fail. But we don't want to always use bool, because the type of the comma-ok variable may be a named bool type, in which case the assignment would fail (or need an explicit conversion). The test case is https://go.dev/cl/404496. Fixes golang/go#52535 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/413894
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/statements.cc18
2 files changed, 12 insertions, 8 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f882812..e20212e 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-6b314f7947b4b31a86c09d166fe6664cd9968824
+6a7ba754e5d98efe0875f1f41f40098e976e7958
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 b3db843..b442830 100644
--- a/gcc/go/gofrontend/statements.cc
+++ b/gcc/go/gofrontend/statements.cc
@@ -1594,9 +1594,9 @@ Tuple_map_assignment_statement::do_lower(Gogo* gogo, Named_object*,
// var present_temp bool
Temporary_statement* present_temp =
- Statement::make_temporary((this->present_->type()->is_sink_type())
- ? Type::make_boolean_type()
- : this->present_->type(),
+ Statement::make_temporary((this->present_->type()->is_boolean_type()
+ ? this->present_->type()
+ : Type::lookup_bool_type()),
NULL, loc);
b->add_statement(present_temp);
@@ -1789,9 +1789,9 @@ Tuple_receive_assignment_statement::do_lower(Gogo*, Named_object*,
// var closed_temp bool
Temporary_statement* closed_temp =
- Statement::make_temporary((this->closed_->type()->is_sink_type())
- ? Type::make_boolean_type()
- : this->closed_->type(),
+ Statement::make_temporary((this->closed_->type()->is_boolean_type()
+ ? this->closed_->type()
+ : Type::lookup_bool_type()),
NULL, loc);
b->add_statement(closed_temp);
@@ -1965,6 +1965,8 @@ Tuple_type_guard_assignment_statement::do_lower(Gogo*, Named_object*,
b->add_statement(s);
res = Expression::make_call_result(call, 1);
+ if (!this->ok_->type()->is_boolean_type())
+ res = Expression::make_cast(Type::lookup_bool_type(), res, loc);
s = Statement::make_assignment(this->ok_, res, loc);
b->add_statement(s);
}
@@ -2001,7 +2003,9 @@ Tuple_type_guard_assignment_statement::lower_to_object_type(
Temporary_statement* ok_temp = NULL;
if (!this->ok_->is_sink_expression())
{
- ok_temp = Statement::make_temporary(this->ok_->type(),
+ ok_temp = Statement::make_temporary((this->ok_->type()->is_boolean_type()
+ ? this->ok_->type()
+ : Type::lookup_bool_type()),
NULL, loc);
b->add_statement(ok_temp);
}