public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Use bool for comma-ok if not already boolean
@ 2022-06-24 18:25 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-06-24 18:25 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

This patch to the Go frontend uses bool for a comma-ok statement if
the variable already has a type that is not a boolean type.  This is a
statement like

    v, ok := m[k]

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.  This fixes
https://go.dev/issue/52535.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2460 bytes --]

3bfc16d86b29600fd559dd733a6909c9441aac25
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f882812d219..e20212e990a 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 b3db843365e..b442830b0b7 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);
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-24 18:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-24 18:25 Go patch committed: Use bool for comma-ok if not already boolean Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).