mirror of
https://github.com/golang/go
synced 2024-11-06 12:36:22 -07:00
6adaf17eaa
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>
46 lines
873 B
Go
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()
|
|
}
|