Go patch committed: Avoid compiler crash in recursive type detection

2019-01-28 Thread Ian Lance Taylor
This patch by Ben Shi fixes the Go frontend to avoid crashing when
handling a recursive type definition like

type T0 T1; type T1 T2; .. type Tn T0

This fixes https://golang.org/issue/25320.

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

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 268230)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-d67c4bf0c42b79d54925ba8c5f23278ee6c3efb6
+5ccb2d8593963e06ec3a35d362b384e82301d9f0
 
 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 268158)
+++ gcc/go/gofrontend/types.cc  (working copy)
@@ -10259,6 +10259,15 @@ Find_type_use::type(Type* type)
  break;
 
case Type::TYPE_NAMED:
+  if (type->named_type() == type->base()->named_type())
+{
+  this->found_ = true;
+  return TRAVERSE_EXIT;
+}
+  else
+   go_assert(saw_errors());
+   break;
+
case Type::TYPE_FORWARD:
  go_assert(saw_errors());
  break;


Go patch committed: avoid compiler crash on invalid programs

2017-09-13 Thread Ian Lance Taylor
This minor patch to the Go frontend avoids crashing the compiler on
some invalid programs.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 252747)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-89e46ae0cde7bebd8e97434355c5b7e57d902613
+0176cbc6dbd2170bfe2eb8904b80ddfe4c946997
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/expressions.cc
===
--- gcc/go/gofrontend/expressions.cc(revision 252746)
+++ gcc/go/gofrontend/expressions.cc(working copy)
@@ -210,7 +210,11 @@ Expression::convert_type_to_interface(Ty
 }
 
   // This should have been checked already.
-  go_assert(lhs_interface_type->implements_interface(rhs_type, NULL));
+  if (!lhs_interface_type->implements_interface(rhs_type, NULL))
+{
+  go_assert(saw_errors());
+  return Expression::make_error(location);
+}
 
   // An interface is a tuple.  If LHS_TYPE is an empty interface type,
   // then the first field is the type descriptor for RHS_TYPE.


Go patch committed: Avoid compiler crash on initialization error

2015-09-15 Thread Ian Lance Taylor
This patch by Chris Manghane to the Go frontend avoids a compiler
crash on an initialization error involving builtin functions.  This
fixes https://golang.org/issue/12319 .  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian
Index: gcc/go/gofrontend/MERGE
===
--- gcc/go/gofrontend/MERGE (revision 227811)
+++ gcc/go/gofrontend/MERGE (working copy)
@@ -1,4 +1,4 @@
-eac8b31fec761c8da0606a70ae0547ff0b12e8db
+01a574c1b2bb244be764b6a18aab980ca0aef43c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: gcc/go/gofrontend/expressions.cc
===
--- gcc/go/gofrontend/expressions.cc(revision 227758)
+++ gcc/go/gofrontend/expressions.cc(working copy)
@@ -6885,11 +6885,6 @@ Builtin_call_expression::do_flatten(Gogo
 Statement_inserter* inserter)
 {
   Location loc = this->location();
-  if (this->is_erroneous_call())
-{
-  go_assert(saw_errors());
-  return Expression::make_error(loc);
-}
 
   switch (this->code_)
 {
@@ -8064,6 +8059,13 @@ Builtin_call_expression::do_get_backend(
 {
   Gogo* gogo = context->gogo();
   Location location = this->location();
+
+  if (this->is_erroneous_call())
+{
+  go_assert(saw_errors());
+  return gogo->backend()->error_expression();
+}
+
   switch (this->code_)
 {
 case BUILTIN_INVALID:


Go patch committed: Avoid compiler crash

2012-03-28 Thread Ian Lance Taylor
This patch from Rémy Oudompheng avoids a Go frontend crash on the valid
Go code

package p
var v struct{ I }
type I interface{}

Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline and 4.7 branch.

Ian

diff -r 652c8036e264 go/gogo.cc
--- a/go/gogo.cc	Wed Mar 28 14:32:28 2012 -0700
+++ b/go/gogo.cc	Wed Mar 28 15:12:54 2012 -0700
@@ -1653,8 +1653,12 @@
   }
 
 case Type::TYPE_STRUCT:
+  // Traverse the field types first in case there is an embedded
+  // field with methods that the struct should inherit.
+  if (t-struct_type()-traverse_field_types(this) == TRAVERSE_EXIT)
+  return TRAVERSE_EXIT;
   t-struct_type()-finalize_methods(this-gogo_);
-  break;
+  return TRAVERSE_SKIP_COMPONENTS;
 
 default:
   break;