Patchwork libgo patch committed: Fix self-referential struct

login
register
mail settings
Submitter Ian Taylor
Date Jan. 27, 2011, 8:39 p.m.
Message ID <mcr1v3yrshy.fsf@google.com>
Download mbox | patch
Permalink /patch/80735/
State New
Headers show

Comments

Ian Taylor - Jan. 27, 2011, 8:39 p.m.
This patch to the Go frontend fixes another case of a self-referential
struct.  In this case the struct had a field whose type was a function
which took an argument which was a pointer to a struct which had a field
which was an array of the original struct.  This patch fixes the problem
by treating fields of function type the same way we treat fields of
pointer type.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r e88ce685d814 go/types.cc
--- a/go/types.cc	Wed Jan 26 16:07:10 2011 -0800
+++ b/go/types.cc	Thu Jan 27 12:36:39 2011 -0800
@@ -3763,7 +3763,7 @@ 
       // Don't follow pointers yet, so that we don't get confused by a
       // pointer to an array of this struct type.
       tree field_type_tree;
-      if (p->type()->points_to() != NULL)
+      if (p->type()->points_to() != NULL || p->type()->function_type() != NULL)
 	{
 	  field_type_tree = ptr_type_node;
 	  has_pointer = true;
@@ -3793,7 +3793,8 @@ 
 	   p != this->fields_->end();
 	   ++p, field = DECL_CHAIN(field))
 	{
-	  if (p->type()->points_to() != NULL)
+	  if (p->type()->points_to() != NULL
+	      || p->type()->function_type() != NULL)
 	    TREE_TYPE(field) = p->type()->get_tree(gogo);
 	}
     }