diff options
| author | David Chase <drchase@google.com> | 2019-10-09 18:06:06 -0400 |
|---|---|---|
| committer | David Chase <drchase@google.com> | 2019-10-15 16:43:44 +0000 |
| commit | 6adaf17eaaa7f2a8ec59a01f5b7280db210b3e75 (patch) | |
| tree | 220e516cae1a828049f9234b9e99cd16ff88760a /test | |
| parent | c2c2ba280c77e76115cf1918d91a509f6bf98390 (diff) | |
| download | go-6adaf17eaaa7f2a8ec59a01f5b7280db210b3e75.tar.xz | |
cmd/compile: preserve statements in late nilcheckelim optimization
When a subsequent load/store of a ptr makes the nil check of that pointer
unnecessary, if their lines differ, change the line of the load/store
to that of the nilcheck, and attempt to rehome the load/store position
instead.
This fix makes profiling less accurate in order to make panics more
informative.
Fixes #33724
Change-Id: Ib9afaac12fe0d0320aea1bf493617facc34034b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/200197
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test')
| -rw-r--r-- | test/codegen/memcombine.go | 4 | ||||
| -rw-r--r-- | test/fixedbugs/issue33724.go | 45 |
2 files changed, 47 insertions, 2 deletions
diff --git a/test/codegen/memcombine.go b/test/codegen/memcombine.go index d5f3af7692..e2d703cb0c 100644 --- a/test/codegen/memcombine.go +++ b/test/codegen/memcombine.go @@ -321,8 +321,8 @@ func fcall_uint32(a, b uint32) (uint32, uint32) { // We want to merge load+op in the first function, but not in the // second. See Issue 19595. func load_op_merge(p, q *int) { - x := *p - *q += x // amd64:`ADDQ\t\(` + x := *p // amd64:`ADDQ\t\(` + *q += x // The combined nilcheck and load would normally have this line number, but we want that combined operation to have the line number of the nil check instead (see #33724). } func load_op_no_merge(p, q *int) { x := *p diff --git a/test/fixedbugs/issue33724.go b/test/fixedbugs/issue33724.go new file mode 100644 index 0000000000..a4ecddc0b3 --- /dev/null +++ b/test/fixedbugs/issue33724.go @@ -0,0 +1,45 @@ +// run +package main + +import ( + "fmt" + "runtime/debug" + "strings" +) + +type Inner struct { + Err int +} + +func (i *Inner) NotExpectedInStackTrace() int { + if i == nil { + return 86 + } + return 17 + i.Err +} + +type Outer struct { + Inner +} + +func ExpectedInStackTrace() { + var o *Outer + println(o.NotExpectedInStackTrace()) +} + +func main() { + defer func() { + if r := recover(); r != nil { + stacktrace := string(debug.Stack()) + if strings.Contains(stacktrace, "NotExpectedInStackTrace") { + fmt.Println("FAIL, stacktrace contains NotExpectedInStackTrace") + } + if !strings.Contains(stacktrace, "ExpectedInStackTrace") { + fmt.Println("FAIL, stacktrace does not contain ExpectedInStackTrace") + } + } else { + fmt.Println("FAIL, should have panicked but did not") + } + }() + ExpectedInStackTrace() +} |
