diff options
author | Russ Cox <rsc@golang.org> | 2014-04-16 13:59:42 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-04-16 13:59:42 -0400 |
commit | 03edd0cabb6c37bc8cb77e056f350711cda6fef2 (patch) | |
tree | eb18a9567494dcf4df09aef7c7060cfcfa87c4eb /src/cmd/6g | |
parent | 5bf8838da134a40ff15a3339286f0c279923b488 (diff) | |
download | go-03edd0cabb6c37bc8cb77e056f350711cda6fef2.tar.gz |
cmd/5g, cmd/6g, cmd/8g: preserve wide values in large functions
In large functions with many variables, the register optimizer
may give up and choose not to track certain variables at all.
In this case, the "nextinnode" information linking together
all the words from a given variable will be incomplete, and
the result may be that only some of a multiword value is
preserved across a call. That confuses the garbage collector,
so don't do that. Instead, mark those variables as having
their address taken, so that they will be preserved at all
calls. It's overkill, but correct.
Tested by hand using the 6g -S output to see that it does fix
the buggy generated code leading to the issue 7726 failure.
There is no automated test because I managed to break the
compiler while writing a test (see issue 7727). I will check
in a test along with the fix to issue 7727.
Fixes issue 7726.
LGTM=khr
R=khr, bradfitz, dave
CC=golang-codereviews
https://codereview.appspot.com/85200043
Diffstat (limited to 'src/cmd/6g')
-rw-r--r-- | src/cmd/6g/reg.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/cmd/6g/reg.c b/src/cmd/6g/reg.c index 3e5b1c586..0c72d6c95 100644 --- a/src/cmd/6g/reg.c +++ b/src/cmd/6g/reg.c @@ -659,6 +659,16 @@ mkvar(Reg *r, Adr *a) if(nvar >= NVAR) { if(debug['w'] > 1 && node != N) fatal("variable not optimized: %#N", node); + + // If we're not tracking a word in a variable, mark the rest as + // having its address taken, so that we keep the whole thing + // live at all calls. otherwise we might optimize away part of + // a variable but not all of it. + for(i=0; i<nvar; i++) { + v = var+i; + if(v->node == node) + v->addr = 1; + } goto none; } |