1
0
mirror of https://github.com/golang/go synced 2024-11-12 09:50:21 -07:00
go/test
Russ Cox ca9975a45e cmd/gc: handle non-escaping address-taken variables better
This CL makes the bitmaps a little more precise about variables
that have their address taken but for which the address does not
escape to the heap, so that the variables are kept in the stack frame
rather than allocated on the heap.

The code before this CL handled these variables by treating every
return statement as using every such variable and depending on
liveness analysis to essentially treat the variable as live during the
entire function. That approach has false positives and (worse) false
negatives. That is, it's both sloppy and buggy:

        func f(b1, b2 bool) {	// x live here! (sloppy)
                if b2 {
                        print(0) // x live here! (sloppy)
                        return
                }
                var z **int
                x := new(int)
                *x = 42
                z = &x
                print(**z) // x live here (conservative)
                if b2 {
                        print(1) // x live here (conservative)
                        return
                }
                for {
                        print(**z) // x not live here (buggy)
                }
        }

The first two liveness annotations (marked sloppy) are clearly
wrong: x cannot be live if it has not yet been declared.

The last liveness annotation (marked buggy) is also wrong:
x is live here as *z, but because there is no return statement
reachable from this point in the code, the analysis treats x as dead.

This CL changes the liveness calculation to mark such variables
live exactly at points in the code reachable from the variable
declaration. This keeps the conservative decisions but fixes
the sloppy and buggy ones.

The CL also detects ambiguously live variables, those that are
being marked live but may not actually have been initialized,
such as in this example:

        func f(b1 bool) {
                var z **int
                if b1 {
                        x := new(int)
                        *x = 42
                        z = &x
                } else {
                        y := new(int)
                        *y = 54
                        z = &y
                }
                print(**z) // x, y live here (conservative)
        }

Since the print statement is reachable from the declaration of x,
x must conservatively be marked live. The same goes for y.
Although both x and y are marked live at the print statement,
clearly only one of them has been initialized. They are both
"ambiguously live".

These ambiguously live variables cause problems for garbage
collection: the collector cannot ignore them but also cannot
depend on them to be initialized to valid pointer values.

Ambiguously live variables do not come up too often in real code,
but recent changes to the way map and interface runtime functions
are invoked has created a large number of ambiguously live
compiler-generated temporary variables. The next CL will adjust
the analysis to understand these temporaries better, to make
ambiguously live variables fairly rare.

Once ambiguously live variables are rare enough, another CL will
introduce code at the beginning of a function to zero those
slots on the stack. At that point the garbage collector and the
stack copying routines will be able to depend on the guarantee that
if a slot is marked as live in a liveness bitmap, it is initialized.

R=khr
CC=golang-codereviews, iant
https://golang.org/cl/51810043
2014-01-16 10:32:30 -05:00
..
bench test: revert unintentional commits 2013-11-19 15:36:13 +04:00
bugs cmd/gc: fix wrong interaction between inlining and embedded builtins. 2012-12-22 19:16:31 +01:00
chan test/chan: avoid wrap-around in memstats comparison 2013-09-20 17:27:56 -07:00
ddd2.dir test: convert tests to run.go whenever possible. 2012-10-10 22:35:27 +02:00
dwarf test: make rundir match compiledir/errorcheckdir. 2013-01-11 22:00:48 +01:00
fixedbugs cmd/gc: return canonical Node* from temp 2014-01-14 10:43:13 -05:00
import2.dir test: convert more tests to rundir/compiledir conventions 2012-10-07 23:22:01 +02:00
import4.dir test: match gccgo import error messages 2013-12-12 19:02:11 -08:00
interface cmd/gc: don't attempt to generate wrappers for blank interface methods 2013-08-19 11:53:34 +10:00
ken go/test/chan1.go: fix typo 2012-02-25 08:47:04 +11:00
method4.dir cmd/gc: do not omit wrapper for expression (interface{...}).F 2014-01-07 13:26:48 +01:00
safe test: adapt old-style tests to new flag parsing. 2013-01-11 22:05:46 +01:00
stress test/stress: fix a goroutine leak in threadRing stresstest 2013-06-03 07:07:31 -07:00
syntax test: match gccgo error messages 2013-12-12 17:18:12 -08:00
64bit.go cmd/gc: Error out on division by constant zero. 2013-01-30 20:21:08 +01:00
235.go
alias1.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
alias.go
append.go
args.go test: run some more tests by default 2012-11-08 09:04:27 -08:00
assign1.go
assign.go
bigalg.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
bigmap.go runtime: handle and test large map values 2012-05-24 22:41:07 -04:00
blank1.go test: match gccgo error messages for blank1.go 2013-09-28 15:19:05 -07:00
blank.go test: revert changes made for Go SSA interpreter test. 2013-10-08 14:36:20 -04:00
bom.go gc: initial BOM is legal. 2012-09-10 13:03:07 -07:00
bombad.go gc: initial BOM is legal. 2012-09-10 13:03:07 -07:00
bounds.go test: prepare for 64-bit ints 2012-09-24 00:06:41 -04:00
chancap.go
char_lit1.go
char_lit.go
closedchan.go
closure.go test: enforce 1 proc in the test 2012-07-01 21:59:50 +04:00
cmp6.go cmd/gc: fix computation of equality class of types. 2013-07-02 09:08:43 +02:00
cmp.go test: invert incorrect condition. 2013-07-16 12:18:00 -04:00
cmplx.go cmd/gc: reject complex calls with mismatched argument types. 2013-03-11 22:55:14 +01:00
cmplxdivide1.go test: use testlib in a few more cases 2012-03-22 02:14:44 +08:00
cmplxdivide.c test: use testlib in a few more cases 2012-03-22 02:14:44 +08:00
cmplxdivide.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
complit1.go
complit.go
compos.go
const1.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
const2.go test: match gccgo error messages 2012-09-28 08:30:30 -07:00
const3.go
const4.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
const5.go cmd/gc: reject non-Go constants 2013-02-01 23:10:02 -05:00
const6.go test: match gccgo error strings. 2013-06-26 18:05:02 +02:00
const.go exp/ssa/interp: (#6 of 5): test interpretation of SSA form of $GOROOT/test/*.go. 2013-02-21 12:48:38 -05:00
convert1.go
convert3.go
convert.go
convlit1.go
convlit.go
convT2X.go cmd/gc: cache itab lookup in convT2I. 2012-07-03 09:09:05 +10:00
copy.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
crlf.go test: use testlib in a few more cases (part 2) 2012-04-20 23:45:43 +08:00
ddd1.go test: match gccgo error messages 2012-09-28 08:30:30 -07:00
ddd2.go test: convert tests to run.go whenever possible. 2012-10-10 22:35:27 +02:00
ddd.go test: enable method expression tests in ddd.go 2012-03-07 11:17:26 -08:00
decl.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
declbad.go test: correct type in declbad.go 2012-10-07 21:52:57 +02:00
defer.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
deferfin.go test: disable a couple of precise GC tests for gccgo 2013-12-12 17:13:27 -08:00
deferprint.go test: add cmpout to testlib 2012-02-24 13:17:26 +11:00
deferprint.out
divide.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
divmod.go all: fix a few spelling errors in source comments 2013-12-27 08:59:02 -08:00
empty.go
env.go
eof1.go
eof.go
errchk test/errchk: use "#!/usr/bin/env perl" shebang line 2013-05-23 04:41:22 +08:00
escape2.go test: avoid future 'declared and not used' error 2013-09-17 15:24:54 -07:00
escape3.go
escape4.go cmd/gc: fix escape analysis bug 2012-09-24 15:53:12 -04:00
escape5.go cmd/gc: move large stack variables to heap 2013-08-08 13:46:30 -04:00
escape.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
float_lit.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
floatcmp.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
for.go
func1.go cmd/gc: ensure unique parameter and result names in function types 2013-03-15 15:24:13 -04:00
func2.go
func3.go
func4.go
func5.go
func6.go
func7.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
func8.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
func.go
funcdup2.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
funcdup.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
gc1.go
gc2.go
gc.go
golden.out cmd/gc: do not generate code for var _ = ... unless necessary 2012-12-30 12:01:53 -05:00
goprint.go test: make goprint.go wait longer for go its routine to execute 2013-04-12 16:04:19 -07:00
goprint.out
goto.go
helloworld.go test: add cmpout to testlib 2012-02-24 13:17:26 +11:00
helloworld.out
if.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
import1.go test: match gccgo import error messages 2013-12-12 19:02:11 -08:00
import2.go test: convert more tests to rundir/compiledir conventions 2012-10-07 23:22:01 +02:00
import4.go test: convert more tests to rundir/compiledir conventions 2012-10-07 23:22:01 +02:00
import5.go gc: disallow absolute import paths 2012-02-29 15:28:36 -05:00
import.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
index0.go test: run index test by default 2012-11-07 12:33:54 -08:00
index1.go test: run index test by default 2012-11-07 12:33:54 -08:00
index2.go test: run index test by default 2012-11-07 12:33:54 -08:00
index.go test: recognize gccgo error message in index.go 2013-09-27 20:38:52 -07:00
indirect1.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
indirect.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
init1.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
init.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
initcomma.go
initialize.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
initializerr.go test: add "duplicate" struct map key test 2012-12-17 11:05:58 -05:00
int_lit.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
intcvt.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
iota.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
label1.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
label.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
linkx.go test: expand run.go's errorcheck, make clear which bugs run 2012-09-23 13:16:14 -04:00
literal.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
live.go cmd/gc: handle non-escaping address-taken variables better 2014-01-16 10:32:30 -05:00
mallocfin.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
map1.go cmd/gc: fix type checking loop 2012-06-07 03:06:40 -04:00
map.go test: fix flaky NaN-key map complexity test 2013-04-07 11:56:15 -07:00
mapnan.go test/mapnan: use time.Now instead of syscall.Getrusage 2013-10-22 18:33:37 -04:00
method1.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
method2.go cmd/gc: fix method values whose receiver is an unnamed interface. 2013-08-29 10:00:58 +02:00
method3.go test: commentary for [h-m]*.go 2012-02-23 18:47:26 +11:00
method4.go test: convert more tests to rundir/compiledir conventions 2012-10-07 23:22:01 +02:00
method5.go cmd/gc: implement method values 2013-03-20 17:11:09 -04:00
method.go test: a number of fixes. 2013-02-11 18:20:52 -05:00
named1.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
named.go gc: return of ideal bool 2012-02-21 22:54:07 -05:00
nil.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
nilcheck.go cmd/gc: &x panics if x does 2013-08-15 14:38:32 -04:00
nilptr2.go test: revert changes made for Go SSA interpreter test. 2013-10-08 14:36:20 -04:00
nilptr3.go cmd/gc: eliminate redundant &x.Field nil checks 2013-09-17 16:54:22 -04:00
nilptr.go test/nilptr: add more tests 2013-09-05 23:06:34 -04:00
nul1.go test: run some more tests by default 2012-11-08 09:04:27 -08:00
parentype.go test/[n-r]*.go: add documentation 2012-02-24 10:30:39 +11:00
peano.go test/[n-r]*.go: add documentation 2012-02-24 10:30:39 +11:00
printbig.go test: add cmpout to testlib 2012-02-24 13:17:26 +11:00
printbig.out
range.go test: a number of fixes. 2013-02-11 18:20:52 -05:00
recover1.go
recover2.go
recover3.go tests: remove two misuses of nil pointers 2013-08-15 11:51:04 -04:00
recover.go test: disable failing tests under ssa/interp. 2013-09-18 14:44:57 -04:00
rename1.go test: fix the fix of the rename tests. 2012-02-24 15:06:32 +11:00
rename.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00
reorder2.go test/[n-r]*.go: add documentation 2012-02-24 10:30:39 +11:00
reorder.go test: a number of fixes. 2013-02-11 18:20:52 -05:00
return.go test: add cases to return.go that gccgo got wrong 2013-08-07 11:31:01 -07:00
rotate0.go test: add rotate.go and fixedbugs/bug313 2013-01-11 22:42:55 +01:00
rotate1.go test: add rotate.go and fixedbugs/bug313 2013-01-11 22:42:55 +01:00
rotate2.go test: add rotate.go and fixedbugs/bug313 2013-01-11 22:42:55 +01:00
rotate3.go test: add rotate.go and fixedbugs/bug313 2013-01-11 22:42:55 +01:00
rotate.go test: add rotate.go and fixedbugs/bug313 2013-01-11 22:42:55 +01:00
run test: minor fixes in run and testlib 2012-09-24 00:06:31 -04:00
run.go all: fix a few spelling errors in source comments 2013-12-27 08:59:02 -08:00
rune.go test/[n-r]*.go: add documentation 2012-02-24 10:30:39 +11:00
runtime.go test/[n-r]*.go: add documentation 2012-02-24 10:30:39 +11:00
shift1.go test/shift1.go: recognize gccgo errors 2013-06-26 08:23:52 -07:00
shift2.go test: add shift expression incorrectly rejected by gccgo. 2013-06-25 08:06:34 +02:00
sieve.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
sigchld.go undo CL 10017045 / 6ec8c49421a0 2013-06-04 21:51:22 -07:00
sigchld.out
simassign.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
sinit.go cmd/gc: do not generate code for var _ = ... unless necessary 2012-12-30 12:01:53 -05:00
sizeof.go test: correct sizeof.go. 2013-06-02 19:10:11 +02:00
slice3.go cmd/gc: support x[i:j:k] 2013-07-01 20:32:36 -04:00
slice3err.go test: match gccgo error messages 2013-12-12 17:18:12 -08:00
solitaire.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
stack.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
string_lit.go test: add []rune case to string_lit.go 2013-12-12 17:17:02 -08:00
stringrange.go all: make Unicode surrogate halves illegal as UTF-8 2012-08-08 14:01:23 -07:00
struct0.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
switch3.go cmd/gc: accept switches on comparable arrays. 2012-08-03 21:47:26 +02:00
switch4.go cmd/gc: disallow fallthrough in final case of switch 2013-03-15 00:35:09 -04:00
switch.go cmd/gc: disallow fallthrough in final case of switch 2013-03-15 00:35:09 -04:00
testlib test/run: process build tags like go/build 2013-08-13 12:25:41 -04:00
torture.go cmd/8g: introduce temporaries in byte multiplication. 2012-12-21 23:46:16 +01:00
turing.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
typecheck.go cmd/gc: silence assignment errors to undefined symbols 2014-01-03 21:03:20 +01:00
typeswitch1.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
typeswitch2.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
typeswitch3.go test: match gccgo error messages 2012-09-28 08:30:30 -07:00
typeswitch.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
undef.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
utf.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
varerr.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
varinit.go test/[n-z]*.go: add documentation 2012-02-24 11:48:19 +11:00
zerodivide.go test: ensure all failing tests exit nonzero. 2013-02-12 13:17:49 -05:00