summaryrefslogtreecommitdiff
path: root/test/escape2.go
Commit message (Collapse)AuthorAgeFilesLines
* cmd/gc: run escape analysis always (even in -N mode)Russ Cox2014-09-241-0/+2
| | | | | | | | | | Fixes issue 8585. Removes some little-used code paths. LGTM=josharian R=golang-codereviews, minux, josharian CC=golang-codereviews, iant, r https://codereview.appspot.com/132970043
* cmd/gc: fix &result escaping into resultRuss Cox2014-06-111-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | There is a hierarchy of location defined by loop depth: -1 = the heap 0 = function results 1 = local variables (and parameters) 2 = local variable declared inside a loop 3 = local variable declared inside a loop inside a loop etc In general if an address from loopdepth n is assigned to something in loop depth m < n, that indicates an extended lifetime of some form that requires a heap allocation. Function results can be local variables too, though, and so they don't actually fit into the hierarchy very well. Treat the address of a function result as level 1 so that if it is written back into a result, the address is treated as escaping. Fixes issue 8185. LGTM=iant R=iant CC=golang-codereviews https://codereview.appspot.com/108870044
* cmd/gc: fix escape analysis for &x inside switch x := v.(type)Russ Cox2014-06-111-0/+10
| | | | | | | | | | | | | | The analysis for &x was using the loop depth on x set during x's declaration. A type switch creates a list of implicit declarations that were not getting initialized with loop depths. Fixes issue 8176. LGTM=iant R=iant CC=golang-codereviews https://codereview.appspot.com/108860043
* cmd/gc: fix escape analysis of func returning indirect of parameterRuss Cox2014-06-031-3/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I introduced this bug when I changed the escape analysis to run in phases based on call graph dependency order, in order to be more precise about inputs escaping back to outputs (functions returning their arguments). Given func f(z **int) *int { return *z } we were tagging the function as 'z does not escape and is not returned', which is all true, but not enough information. If used as: var x int p := &x q := &p leak(f(q)) then the compiler might try to keep x, p, and q all on the stack, since (according to the recorded information) nothing interesting ends up being passed to leak. In fact since f returns *q = p, &x is passed to leak and x needs to be heap allocated. To trigger the bug, you need a chain that the compiler wants to keep on the stack (like x, p, q above), and you need a function that returns an indirect of its argument, and you need to pass the head of the chain to that function. This doesn't come up very often: this bug has been present since June 2012 (between Go 1 and Go 1.1) and we haven't seen it until now. It helps that most functions that return indirects are getters that are simple enough to be inlined, avoiding the bug. Earlier versions of Go also had the benefit that if &x really wasn't used beyond x's lifetime, nothing broke if you put &x in a heap-allocated structure accidentally. With the new stack copying, though, heap-allocated structures containing &x are not updated when the stack is copied and x moves, leading to crashes in Go 1.3 that were not crashes in Go 1.2 or Go 1.1. The fix is in two parts. First, in the analysis of a function, recognize when a value obtained via indirect of a parameter ends up being returned. Mark those parameters as having content escape back to the return results (but we don't bother to write down which result). Second, when using the analysis to analyze, say, f(q), mark parameters with content escaping as having any indirections escape to the heap. (We don't bother trying to match the content to the return value.) The fix could be less precise (simpler). In the first part we might mark all content-escaping parameters as plain escaping, and then the second part could be dropped. Or we might assume that when calling f(q) all the things pointed at by q escape always (for any f and q). The fix could also be more precise (more complex). We might record the specific mapping from parameter to result along with the number of indirects from the parameter to the thing being returned as the result, and then at the call sites we could set up exactly the right graph for the called function. That would make notleaks(f(q)) be able to keep x on the stack, because the reuslt of f(q) isn't passed to anything that leaks it. The less precise the fix, the more stack allocations become heap allocations. This fix is exactly as precise as it needs to be so that none of the current stack allocations in the standard library turn into heap allocations. Fixes issue 8120. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews, khr, r https://codereview.appspot.com/102040046
* cmd/gc: fix escape analysis for slice of arrayRuss Cox2014-05-121-0/+32
| | | | | | | | | Fixes issue 7931. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://codereview.appspot.com/100390044
* cmd/gc: fix ... escape analysis bugRuss Cox2014-05-091-8/+20
| | | | | | | | | | | | | | If the ... element type contained no pointers, then the escape analysis did not track the ... itself. This manifested in an escaping ...byte being treated as non-escaping. Fixes issue 7934. LGTM=iant R=golang-codereviews, iant CC=golang-codereviews https://codereview.appspot.com/100310043
* cmd/gc: relax address-of escape analysisRuss Cox2014-02-131-0/+10
| | | | | | | | | | | | | | | | | | Make the loop nesting depth of &x depend on where x is declared, not on where the &x appears. The latter is only a conservative estimate of the former. Being more careful can avoid some variables escaping, and it is easier to reason about. It would have avoided issue 7313, although that was still a bug worth fixing. Not much effect in the tree: one variable in the whole tree is saved from a heap allocation (something in x509 parsing). LGTM=daniel.morsing R=daniel.morsing CC=golang-codereviews https://codereview.appspot.com/62380043
* cmd/gc: for loop init statement misanalyzed by escape analysisDaniel Morsing2014-02-131-0/+32
| | | | | | | | | | | Logically, the init statement is in the enclosing scopes loopdepth, not inside the for loop. Fixes issue 7313. LGTM=rsc R=golang-codereviews, gobot, rsc CC=golang-codereviews https://codereview.appspot.com/62430043
* test: avoid future 'declared and not used' errorRobert Griesemer2013-09-171-0/+1
| | | | | | | | See also issue 6414. R=r CC=golang-dev https://codereview.appspot.com/13683044
* cmd/gc: fix escape analysis orderingRuss Cox2013-06-251-0/+19
| | | | | | | | | | | | | | | | | | Functions without bodies were excluded from the ordering logic, because when I wrote the ordering logic there was no reason to analyze them. But then we added //go:noescape tags that need analysis, and we didn't update the ordering logic. So in the absence of good ordering, //go:noescape only worked if it appeared before the use in the source code. Fixes issue 5773. R=golang-dev, r CC=golang-dev https://codereview.appspot.com/10570043
* test: add test for issue 3888.R?my Oudompheng2013-05-221-0/+12
| | | | | | R=golang-dev, bradfitz CC=golang-dev https://codereview.appspot.com/9676043
* cmd/gc: fix escape analysis of method valuesRuss Cox2013-03-201-0/+22
| | | | | | R=ken2 CC=golang-dev https://codereview.appspot.com/7518050
* cmd/gc: fix escape analysis bug.R?my Oudompheng2013-03-151-2/+5
| | | | | | | | | | | | It used to not mark parameters as escaping if only one of the fields it points to leaks out of the function. This causes problems when importing from another package. Fixes issue 4964. R=rsc, lvd, dvyukov, daniel.morsing CC=golang-dev https://codereview.appspot.com/7648045
* cmd/gc: add way to specify 'noescape' for extern funcsRuss Cox2013-02-051-0/+26
| | | | | | | | | | | | A new comment directive //go:noescape instructs the compiler that the following external (no body) func declaration should be treated as if none of its arguments escape to the heap. Fixes issue 4099. R=golang-dev, dave, minux.ma, daniel.morsing, remyoudompheng, adg, agl, iant CC=golang-dev https://codereview.appspot.com/7289048
* cmd/gc: fix escape analysisRuss Cox2013-02-041-0/+16
| | | | | | | | | | | | | | | | If the analysis reached a node twice, then the analysis was cut off. However, if the second arrival is at a lower depth (closer to escaping) then it is important to repeat the traversal. The repeating must be cut off at some point to avoid the occasional infinite recursion. This CL cuts it off as soon as possible while still passing all tests. Fixes issue 4751. R=ken2 CC=golang-dev, lvd https://codereview.appspot.com/7303043
* cmd/gc: remove an incorrect assertion in escape analysis.R?my Oudompheng2012-12-201-51/+66
| | | | | | | | | | | | | A fatal error used to happen when escassign-ing a multiple function return to a single node. However, the situation naturally appears when using "go f(g())" or "defer f(g())", because g() is escassign-ed to sink. Fixes issue 4529. R=golang-dev, lvd, minux.ma, rsc CC=golang-dev https://codereview.appspot.com/6920060
* cmd/gc: escape analysis to track flow of in to out parameters.Luuk van Dijk2012-10-291-6/+20
| | | | | | | | | | | | | | | | includes step 0: synthesize outparams, from 6600044 includes step 1,2: give outparams loopdepth 0 and verify unchanged results generate esc:$mask tags, but still tie to sink if a param has mask != 0 from 6610054 adds final steps: - have esccall generate n->escretval, a list of nodes the function results flow to - use these in esccall and ORETURN/OAS2FUNC/and f(g()) - only tie parameters to sink if tag is absent, otherwise according to mask, tie them to escretval R=rsc, bradfitz CC=dave, gobot, golang-dev, iant, rsc http://codereview.appspot.com/6741044
* cmd/gc: fix escape analysis bugRuss Cox2012-09-241-0/+18
| | | | | | | | | Was not handling &x.y[0] and &x.y.z correctly where y is an array or struct-valued field (not a pointer). R=ken2 CC=golang-dev http://codereview.appspot.com/6551059
* test: expand run.go's errorcheck, make clear which bugs runRuss Cox2012-09-231-1/+1
| | | | | | | | | | | | | | | | Today, if run.go doesn't understand a test header line it just ignores the test, making it too easy to write or edit tests that are not actually being run. - expand errorcheck to accept flags, so that bounds.go and escape*.go can run. - create a whitelist of skippable tests in run.go; skipping others is an error. - mark all skipped tests at top of file. Update issue 4139. R=golang-dev, bradfitz CC=golang-dev http://codereview.appspot.com/6549054
* cmd/gc: fix escape analysis bug with variable capture in loops.R?my Oudompheng2012-08-311-0/+13
| | | | | | | | Fixes issue 3975. R=rsc, lvd CC=golang-dev, remy http://codereview.appspot.com/6475061
* cmd/gc: fix addresses escaping through closures called in-place.Luuk van Dijk2012-04-231-2/+135
| | | | | | | | | | Fixes issue 3545. R=rsc CC=golang-dev http://codereview.appspot.com/6061043 Committer: Russ Cox <rsc@golang.org>
* gc: fix escape analysis + inlining + closure bugRuss Cox2012-02-231-1/+1
| | | | | | R=ken2 CC=golang-dev, lvd http://codereview.appspot.com/5693056
* test: explanatory comments [c-g]*Rob Pike2012-02-191-0/+3
| | | | | | R=golang-dev, bradfitz CC=golang-dev http://codereview.appspot.com/5656103
* gc: avoid false positives when using scalar struct fields.R?my Oudompheng2012-01-121-6/+36
| | | | | | | | | | | | The escape analysis code does not make a distinction between scalar and pointers fields in structs. Non-pointer fields that escape should not make the whole struct escape. R=lvd, rsc CC=golang-dev, remy http://codereview.appspot.com/5489128 Committer: Luuk van Dijk <lvd@golang.org>
* gc: enable inlining by defaultRuss Cox2012-01-101-1/+1
| | | | | | R=lvd, r CC=golang-dev http://codereview.appspot.com/5531058
* gc: better loopdepth analysis for labelsLuuk van Dijk2011-12-151-0/+21
| | | | | | | | | This avoids degraded performance caused by extra labels emitted by inlining (breaking strconv ftoa alloc count unittest) and is better in any case. R=rsc CC=golang-dev http://codereview.appspot.com/5483071
* gc: use gofmt spacing when printing map typeRuss Cox2011-12-021-2/+2
| | | | | | R=ken2 CC=golang-dev http://codereview.appspot.com/5450071
* gc: small fixes for printing.Luuk van Dijk2011-11-021-3/+3
| | | | | | | | | | | | | mark OADDR inserted by typecheck as implicit OCOPY takes ->left and ->right, not ->list OMAKE*'s can all have arguments precedence for OIND was initalized twice fixes issue 2414 R=rsc, dave CC=golang-dev http://codereview.appspot.com/5319065
* gc: test + fix escape analysis bugRuss Cox2011-11-011-70/+88
| | | | | | R=lvd CC=golang-dev http://codereview.appspot.com/5333049
* gc: changes to export format in preparation for inlining.Luuk van Dijk2011-10-081-102/+102
| | | | | | | | | string literals used as package qualifiers are now prefixed with '@' which obviates the need for the extra ':' before tags. R=rsc, gri, lvd CC=golang-dev http://codereview.appspot.com/5129057
* gc: treat DOTMETH like DOT in escape analysis.Luuk van Dijk2011-09-071-0/+8
| | | | | | | | Fixes issue 2225 R=rsc, nigeltao, dave CC=bradfitz, golang-dev, mikioh.mikioh http://codereview.appspot.com/4972056
* gc: fix label recursion bugsRuss Cox2011-09-011-0/+205
| | | | | | | | | | | | | | | | Was keeping a pointer to the labeled statement in n->right, which meant that generic traversals of the tree visited it twice. That combined with aggressive flattening of the block structure when possible during parsing meant that the kinds of label: code label: code label: code sequences generated by yacc were giving the recursion 2? paths through the program. Fixes issue 2212. R=lvd CC=golang-dev http://codereview.appspot.com/4960050
* gc: fix arm buildRuss Cox2011-08-281-0/+6
| | | | | | | | | | | | | | | | Escape analysis was incorrectly assuming that functions without bodies don't leak their parameters. This meant that sync/atomic's TestAddInt64 was allocating x on its stack, and then x was not properly aligned for use with the atomic 64-bit instructions. Obviously we should figure out the alignment story on 5g too, but this fix is correct and should restore the build to 'ok'. TBR=lvd CC=golang-dev http://codereview.appspot.com/4964047
* gc: tweak and enable escape analysisRuss Cox2011-08-281-196/+271
| | | | | | | | | | | | | | | | -s now means *disable* escape analysis. Fix escape leaks for struct/slice/map literals. Add ... tracking. Rewrite new(T) and slice literal into stack allocation when safe. Add annotations to reflect. Reflect is too chummy with the compiler, so changes like these affect it more than they should. R=lvd, dave, gustavo CC=golang-dev http://codereview.appspot.com/4954043
* gc: fix some spurious leaksRuss Cox2011-08-251-0/+86
| | | | | | | | Probably will spark some discussion. ? R=lvd CC=golang-dev http://codereview.appspot.com/4948041
* gc: Escape analysis.Luuk van Dijk2011-08-241-0/+615
For now it's switch-on-and-offable with -s, and the effects can be inspected with -m. Defaults are the old codepaths. R=rsc CC=golang-dev http://codereview.appspot.com/4634073