From 064acace5b39308e19419e9f0e5b8a2e68f14a85 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 21 Jul 2014 20:56:44 -0700 Subject: [PATCH] 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 --- src/cmd/gc/gen.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cmd/gc/gen.c b/src/cmd/gc/gen.c index cf630f3484..908a5e53d9 100644 --- a/src/cmd/gc/gen.c +++ b/src/cmd/gc/gen.c @@ -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); -- 2.50.0