]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: in the runtime package, don't promote any decls to the heap.
authorKeith Randall <khr@golang.org>
Tue, 22 Jul 2014 03:56:44 +0000 (20:56 -0700)
committerKeith Randall <khr@golang.org>
Tue, 22 Jul 2014 03:56:44 +0000 (20:56 -0700)
In the runtime, we want to control where allocations happen.
In particular, we don't want the code implementing malloc to
itself trigger a malloc.  This change prevents the compiler
from inserting mallocs on our behalf (due to escaping declarations).

This check does not trigger on the current runtime code.

Note: Composite literals are still allowed.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/105280047

src/cmd/gc/gen.c

index cf630f34843186ad834dcb390b738b9039e34afb..908a5e53d980627c793e469807b483a674a27206 100644 (file)
@@ -584,6 +584,8 @@ cgen_dcl(Node *n)
        }
        if(!(n->class & PHEAP))
                return;
+       if(compiling_runtime)
+               fatal("%N escapes to heap, not allowed in runtime.", n);
        if(n->alloc == nil)
                n->alloc = callnew(n->type);
        cgen_as(n->heapaddr, n->alloc);