diff options
author | Than McIntosh <thanm@google.com> | 2021-02-24 12:55:52 -0500 |
---|---|---|
committer | Than McIntosh <thanm@google.com> | 2021-03-23 23:08:19 +0000 |
commit | 769d4b68ef72125de068a060220c3dbd9ba65c43 (patch) | |
tree | 9a54b697bcc1a1fb24c81bc06376e255c000693b /src/runtime/race/output_test.go | |
parent | 4e27aa6cd2c3f579328e3b490780664ade34053d (diff) | |
download | go-769d4b68ef72125de068a060220c3dbd9ba65c43.tar.gz go-769d4b68ef72125de068a060220c3dbd9ba65c43.zip |
cmd/compile: wrap/desugar defer calls for register abi
Adds code to the compiler's "order" phase to rewrite go and defer
statements to always be argument-less. E.g.
defer f(x,y) => x1, y1 := x, y
defer func() { f(x1, y1) }
This transformation is not beneficial on its own, but it helps
simplify runtime defer handling for the new register ABI (when
invoking deferred functions on the panic path, the runtime doesn't
need to manage the complexity of determining which args to pass in
register vs memory).
This feature is currently enabled by default if GOEXPERIMENT=regabi or
GOEXPERIMENT=regabidefer is in effect.
Included in this CL are some workarounds in the runtime to insure that
"go" statement targets in the runtime are argument-less already (since
wrapping them can potentially introduce heap-allocated closures, which
are currently not allowed). The expectation is that these workarounds
will be temporary, and can go away once we either A) change the rules
about heap-allocated closures, or B) implement some other scheme for
handling go statements.
Change-Id: I01060d79a6b140c6f0838d6e6813f807ccdca319
Reviewed-on: https://go-review.googlesource.com/c/go/+/298669
Trust: Than McIntosh <thanm@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/runtime/race/output_test.go')
-rw-r--r-- | src/runtime/race/output_test.go | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/runtime/race/output_test.go b/src/runtime/race/output_test.go index 4a959d9aba4..2a2197ae262 100644 --- a/src/runtime/race/output_test.go +++ b/src/runtime/race/output_test.go @@ -106,6 +106,8 @@ var tests = []struct { {"simple", "run", "", "atexit_sleep_ms=0", ` package main import "time" +var xptr *int +var donechan chan bool func main() { done := make(chan bool) x := 0 @@ -117,32 +119,34 @@ func store(x *int, v int) { *x = v } func startRacer(x *int, done chan bool) { - go racer(x, done) + xptr = x + donechan = done + go racer() } -func racer(x *int, done chan bool) { +func racer() { time.Sleep(10*time.Millisecond) - store(x, 42) - done <- true + store(xptr, 42) + donechan <- true } `, []string{`================== WARNING: DATA RACE Write at 0x[0-9,a-f]+ by goroutine [0-9]: main\.store\(\) - .+/main\.go:12 \+0x[0-9,a-f]+ + .+/main\.go:14 \+0x[0-9,a-f]+ main\.racer\(\) - .+/main\.go:19 \+0x[0-9,a-f]+ + .+/main\.go:23 \+0x[0-9,a-f]+ Previous write at 0x[0-9,a-f]+ by main goroutine: main\.store\(\) - .+/main\.go:12 \+0x[0-9,a-f]+ + .+/main\.go:14 \+0x[0-9,a-f]+ main\.main\(\) - .+/main\.go:8 \+0x[0-9,a-f]+ + .+/main\.go:10 \+0x[0-9,a-f]+ Goroutine [0-9] \(running\) created at: main\.startRacer\(\) - .+/main\.go:15 \+0x[0-9,a-f]+ + .+/main\.go:19 \+0x[0-9,a-f]+ main\.main\(\) - .+/main\.go:7 \+0x[0-9,a-f]+ + .+/main\.go:9 \+0x[0-9,a-f]+ ================== Found 1 data race\(s\) exit status 66 @@ -239,15 +243,15 @@ func main() { package main var x int - +var c chan int func main() { - c := make(chan int) - go f(c) + c = make(chan int) + go f() x = 1 <-c } -func f(c chan int) { +func f() { g(c) } |