mirror of
https://github.com/golang/go
synced 2024-11-22 00:34:40 -07:00
gc: fix use of stackallocated AST node in generation of static initialisation code.
Fixes #2529 R=rsc, rogpeppe CC=golang-dev https://golang.org/cl/5483048
This commit is contained in:
parent
5fa18e1061
commit
e1b1a5fea2
@ -302,18 +302,18 @@ staticcopy(Node *l, Node *r, NodeList **out)
|
|||||||
n1.type = e->expr->type;
|
n1.type = e->expr->type;
|
||||||
if(e->expr->op == OLITERAL)
|
if(e->expr->op == OLITERAL)
|
||||||
gdata(&n1, e->expr, n1.type->width);
|
gdata(&n1, e->expr, n1.type->width);
|
||||||
else if(staticassign(&n1, e->expr, out)) {
|
else {
|
||||||
// Done
|
|
||||||
} else {
|
|
||||||
// Requires computation, but we're
|
|
||||||
// copying someone else's computation.
|
|
||||||
ll = nod(OXXX, N, N);
|
ll = nod(OXXX, N, N);
|
||||||
*ll = n1;
|
*ll = n1;
|
||||||
rr = nod(OXXX, N, N);
|
if(!staticassign(ll, e->expr, out)) {
|
||||||
*rr = *orig;
|
// Requires computation, but we're
|
||||||
rr->type = ll->type;
|
// copying someone else's computation.
|
||||||
rr->xoffset += e->xoffset;
|
rr = nod(OXXX, N, N);
|
||||||
*out = list(*out, nod(OAS, ll, rr));
|
*rr = *orig;
|
||||||
|
rr->type = ll->type;
|
||||||
|
rr->xoffset += e->xoffset;
|
||||||
|
*out = list(*out, nod(OAS, ll, rr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@ -407,12 +407,11 @@ staticassign(Node *l, Node *r, NodeList **out)
|
|||||||
n1.type = e->expr->type;
|
n1.type = e->expr->type;
|
||||||
if(e->expr->op == OLITERAL)
|
if(e->expr->op == OLITERAL)
|
||||||
gdata(&n1, e->expr, n1.type->width);
|
gdata(&n1, e->expr, n1.type->width);
|
||||||
else if(staticassign(&n1, e->expr, out)) {
|
else {
|
||||||
// done
|
|
||||||
} else {
|
|
||||||
a = nod(OXXX, N, N);
|
a = nod(OXXX, N, N);
|
||||||
*a = n1;
|
*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;
|
return 1;
|
||||||
|
7
test/fixedbugs/bug382.dir/pkg.go
Normal file
7
test/fixedbugs/bug382.dir/pkg.go
Normal file
@ -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
|
10
test/fixedbugs/bug382.go
Normal file
10
test/fixedbugs/bug382.go
Normal file
@ -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}
|
Loading…
Reference in New Issue
Block a user