]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix use of stackallocated AST node in generation of static initialisation code.
authorLuuk van Dijk <lvd@golang.org>
Tue, 13 Dec 2011 08:09:10 +0000 (09:09 +0100)
committerLuuk van Dijk <lvd@golang.org>
Tue, 13 Dec 2011 08:09:10 +0000 (09:09 +0100)
Fixes #2529

R=rsc, rogpeppe
CC=golang-dev
https://golang.org/cl/5483048

src/cmd/gc/sinit.c
test/fixedbugs/bug382.dir/pkg.go [new file with mode: 0644]
test/fixedbugs/bug382.go [new file with mode: 0644]

index 3ef914a60e7c35fdda753d523443c98222324eb0..8798d2136bdaa82a5fd9d3f2a39e391c4e366363 100644 (file)
@@ -302,18 +302,18 @@ staticcopy(Node *l, Node *r, NodeList **out)
                        n1.type = e->expr->type;
                        if(e->expr->op == OLITERAL)
                                gdata(&n1, e->expr, n1.type->width);
-                       else if(staticassign(&n1, e->expr, out)) {
-                               // Done
-                       } else {
-                               // Requires computation, but we're
-                               // copying someone else's computation.
+                       else {
                                ll = nod(OXXX, N, N);
                                *ll = n1;
-                               rr = nod(OXXX, N, N);
-                               *rr = *orig;
-                               rr->type = ll->type;
-                               rr->xoffset += e->xoffset;
-                               *out = list(*out, nod(OAS, ll, rr));
+                               if(!staticassign(ll, e->expr, out)) {
+                                       // Requires computation, but we're
+                                       // copying someone else's computation.
+                                       rr = nod(OXXX, N, N);
+                                       *rr = *orig;
+                                       rr->type = ll->type;
+                                       rr->xoffset += e->xoffset;
+                                       *out = list(*out, nod(OAS, ll, rr));
+                               }
                        }
                }
                return 1;
@@ -407,12 +407,11 @@ staticassign(Node *l, Node *r, NodeList **out)
                        n1.type = e->expr->type;
                        if(e->expr->op == OLITERAL)
                                gdata(&n1, e->expr, n1.type->width);
-                       else if(staticassign(&n1, e->expr, out)) {
-                               // done
-                       } else {
+                       else {
                                a = nod(OXXX, N, N);
                                *a = n1;
-                               *out = list(*out, nod(OAS, a, e->expr));
+                               if(!staticassign(a, e->expr, out))
+                                       *out = list(*out, nod(OAS, a, e->expr));
                        }
                }
                return 1;
diff --git a/test/fixedbugs/bug382.dir/pkg.go b/test/fixedbugs/bug382.dir/pkg.go
new file mode 100644 (file)
index 0000000..f8d75d4
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package pkg
+type T struct {}
+var E T
diff --git a/test/fixedbugs/bug382.go b/test/fixedbugs/bug382.go
new file mode 100644 (file)
index 0000000..6212fbf
--- /dev/null
@@ -0,0 +1,10 @@
+// $G $D/$F.dir/pkg.go && $G $D/$F.go || echo "Bug 382"
+
+// Issue 2529
+
+package main
+import "./pkg"
+
+var x = pkg.E
+
+var fo = struct {F pkg.T}{F: x}