compiler: avoid generating unnamed bool type descriptor
authorIan Lance Taylor <iant@golang.org>
Fri, 10 Jul 2020 20:43:09 +0000 (13:43 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 11 Jul 2020 19:41:28 +0000 (12:41 -0700)
We were generating it in cases where a boolean expression was
converted directly to an empty interface type.

Fixes golang/go#40152

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/242002

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/gogo.cc
gcc/go/gofrontend/names.cc

index c65fd8eecfc29ff3ec40ff99efdbdbc75e700f91..7bec9a8a78e022a81ba9e2a28e5ae2381e423b8d 100644 (file)
@@ -1,4 +1,4 @@
-ce70fa16a73e3f162de01deab6b5d17783e6b76b
+9703ad5fa23ca63062cb403bd12bc7da4d7845bd
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index deac87448f33e42f7ddf7c9ae7ce890487839a14..327f9403b39d8665342f8d0fa5a348a9e7707bd8 100644 (file)
@@ -6041,10 +6041,7 @@ Binary_expression::do_lower(Gogo* gogo, Named_object*,
                                                     &right_nc, location,
                                                     &result))
              return this;
-           return Expression::make_cast(Type::make_boolean_type(),
-                                        Expression::make_boolean(result,
-                                                                 location),
-                                        location);
+           return Expression::make_boolean(result, location);
          }
        else
          {
index 212ef45a29c2a976551322f7ad2421b5d080d8c9..c1021e5679c1b53cdecf3d54213025afa7201264 100644 (file)
@@ -3309,7 +3309,11 @@ Remove_deadcode::expression(Expression** pexpr)
       && be->boolean_constant_value(&bval)
       && (be->op() == OPERATOR_ANDAND
           || be->op() == OPERATOR_OROR))
-    *pexpr = Expression::make_boolean(bval, be->location());
+    {
+      *pexpr = Expression::make_boolean(bval, be->location());
+      Type_context context(NULL, false);
+      (*pexpr)->determine_type(&context);
+    }
   return TRAVERSE_CONTINUE;
 }
 
index a721a364212bec751f4f4b7cf84c5b0d33aee294..1f0a54502dbad729d1c7d574aa490896c1c6125d 100644 (file)
@@ -975,7 +975,14 @@ Gogo::type_descriptor_name(const Type* type, Named_type* nt)
     return "unsafe.Pointer..d";
 
   if (nt == NULL)
-    return "type.." + type->mangled_name(this);
+    {
+      // Sanity check: we should never generate a type descriptor for
+      // an unnamed primitive type.  For those we should always be
+      // using a named type, like "int".
+      go_assert(!type->is_basic_type());
+
+      return "type.." + type->mangled_name(this);
+    }
 
   std::string ret;
   Named_object* no = nt->named_object();