Commit dbee8ad0 authored by Daniel Morsing's avatar Daniel Morsing

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
parent 72c4ee1a
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment