Commit 064acace authored by Keith Randall's avatar Keith Randall

cmd/gc: in the runtime package, don't promote any decls to the heap.

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
parent 76f1b901
...@@ -584,6 +584,8 @@ cgen_dcl(Node *n) ...@@ -584,6 +584,8 @@ cgen_dcl(Node *n)
} }
if(!(n->class & PHEAP)) if(!(n->class & PHEAP))
return; return;
if(compiling_runtime)
fatal("%N escapes to heap, not allowed in runtime.", n);
if(n->alloc == nil) if(n->alloc == nil)
n->alloc = callnew(n->type); n->alloc = callnew(n->type);
cgen_as(n->heapaddr, n->alloc); cgen_as(n->heapaddr, n->alloc);
......
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