mirror of https://github.com/golang/go.git
cmd/cc: reject unions containing pointers
If a union contains a pointer, it will mess up the garbage collector, causing memory corruption. R=golang-dev, dave, nightlyone, adg, dvyukov, bradfitz, minux.ma, r, iant CC=golang-dev https://golang.org/cl/8469043
This commit is contained in:
parent
72c4ee1a9d
commit
dbee8ad0f9
|
|
@ -554,6 +554,28 @@ newlist(Node *l, Node *r)
|
|||
return new(OLIST, l, r);
|
||||
}
|
||||
|
||||
static int
|
||||
haspointers(Type *t)
|
||||
{
|
||||
Type *fld;
|
||||
|
||||
switch(t->etype) {
|
||||
case TSTRUCT:
|
||||
for(fld = t->link; fld != T; fld = fld->down) {
|
||||
if(haspointers(fld))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
case TARRAY:
|
||||
return haspointers(t->link);
|
||||
case TFUNC:
|
||||
case TIND:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sualign(Type *t)
|
||||
{
|
||||
|
|
@ -608,6 +630,9 @@ sualign(Type *t)
|
|||
diag(Z, "incomplete union element");
|
||||
l->offset = 0;
|
||||
l->shift = 0;
|
||||
if((debug['q'] || debug['Q']) && haspointers(l))
|
||||
diag(Z, "precise garbage collector cannot handle unions with pointers");
|
||||
|
||||
o = align(align(0, l, Ael1, &maxal), l, Ael2, &maxal);
|
||||
if(o > w)
|
||||
w = o;
|
||||
|
|
|
|||
Loading…
Reference in New Issue