diff mbox series

Go patch committed: fix crash on struct that embeds pointer type

Message ID CAOyqgcVTv0i4_Nf5n4rA10PtuwOS9wM9uitZs5x3+62=hH9rgg@mail.gmail.com
State New
Headers show
Series Go patch committed: fix crash on struct that embeds pointer type | expand

Commit Message

Ian Lance Taylor Sept. 27, 2017, 5:47 p.m. UTC
This patch by Than McIntosh fixes a crash in the Go frontend that
incorrectly embeds a pointer type.  This fixes
https://golang.org/issue/22050.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
diff mbox series

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 253231)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-cdf1f58c7578980e1d1949680c7e404961b7c153
+11b7dae7de94215e92eb46e703cfecd76c0a3282
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/types.cc
===================================================================
--- gcc/go/gofrontend/types.cc	(revision 253025)
+++ gcc/go/gofrontend/types.cc	(working copy)
@@ -5842,7 +5842,9 @@  Struct_type::do_verify()
       Type* t = p->type();
       if (p->is_anonymous())
 	{
-	  if (t->named_type() != NULL && t->points_to() != NULL)
+	  if ((t->named_type() != NULL && t->points_to() != NULL)
+              || (t->named_type() == NULL && t->points_to() != NULL
+                  && t->points_to()->points_to() != NULL))
 	    {
 	      go_error_at(p->location(), "embedded type may not be a pointer");
 	      p->set_type(Type::make_error_type());
@@ -11848,6 +11850,12 @@  Type::bind_field_or_method(Gogo* gogo, c
 	      go_assert(expr->type()->struct_type() == st);
 	    }
 	  ret = st->field_reference(expr, name, location);
+          if (ret == NULL)
+            {
+              go_error_at(location, "type has no field %qs",
+                          Gogo::message_name(name).c_str());
+              return Expression::make_error(location);
+            }
 	}
       else if (it != NULL && it->find_method(name) != NULL)
 	ret = Expression::make_interface_field_reference(expr, name,