1
0
mirror of https://github.com/golang/go synced 2024-11-06 12:36:22 -07:00
go/test/fixedbugs/issue33724.go
David Chase 6adaf17eaa 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>
2019-10-15 16:43:44 +00:00

46 lines
873 B
Go

// 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()
}