Commit 48ef0105 authored by Keith Randall's avatar Keith Randall Committed by Keith Randall

cmd/compile: handle new panicindex/slice names in optimizations

These new calls should not prevent NOSPLIT promotion, like the old ones.
These new calls should not prevent racefuncenter/exit removal.

(The latter was already true, as the new calls are not yet lowered
to StaticCalls at the point where racefuncenter/exit removal is done.)

Add tests to make sure we don't regress (again).

Fixes #31219

Change-Id: I3fb6b17cdd32c425829f1e2498defa813a5a9ace
Reviewed-on: https://go-review.googlesource.com/c/go/+/170639
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIlya Tocar <ilya.tocar@intel.com>
parent 60736733
...@@ -1129,17 +1129,20 @@ func needRaceCleanup(sym interface{}, v *Value) bool { ...@@ -1129,17 +1129,20 @@ func needRaceCleanup(sym interface{}, v *Value) bool {
for _, v := range b.Values { for _, v := range b.Values {
switch v.Op { switch v.Op {
case OpStaticCall: case OpStaticCall:
switch v.Aux.(fmt.Stringer).String() {
case "runtime.racefuncenter", "runtime.racefuncexit", "runtime.panicindex",
"runtime.panicslice", "runtime.panicdivide", "runtime.panicwrap",
"runtime.panicshift":
// Check for racefuncenter will encounter racefuncexit and vice versa. // Check for racefuncenter will encounter racefuncexit and vice versa.
// Allow calls to panic* // Allow calls to panic*
default: s := v.Aux.(fmt.Stringer).String()
// If we encountered any call, we need to keep racefunc*, switch s {
// for accurate stacktraces. case "runtime.racefuncenter", "runtime.racefuncexit",
return false "runtime.panicdivide", "runtime.panicwrap",
"runtime.panicshift":
continue
} }
// If we encountered any call, we need to keep racefunc*,
// for accurate stacktraces.
return false
case OpPanicBounds, OpPanicExtend:
// Note: these are panic generators that are ok (like the static calls above).
case OpClosureCall, OpInterCall: case OpClosureCall, OpInterCall:
// We must keep the race functions if there are any other call types. // We must keep the race functions if there are any other call types.
return false return false
......
...@@ -975,7 +975,13 @@ func isZeroArgRuntimeCall(s *obj.LSym) bool { ...@@ -975,7 +975,13 @@ func isZeroArgRuntimeCall(s *obj.LSym) bool {
return false return false
} }
switch s.Name { switch s.Name {
case "runtime.panicindex", "runtime.panicslice", "runtime.panicdivide", "runtime.panicwrap", "runtime.panicshift": case "runtime.panicdivide", "runtime.panicwrap", "runtime.panicshift":
return true
}
if strings.HasPrefix(s.Name, "runtime.panicIndex") || strings.HasPrefix(s.Name, "runtime.panicSlice") {
// These functions do take arguments (in registers),
// but use no stack before they do a stack check. We
// should include them. See issue 31219.
return true return true
} }
return false return false
......
// asmcheck -race
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package codegen
// Check that we elide racefuncenter/racefuncexit for
// functions with no calls (but which might panic
// in various ways). See issue 31219.
// amd64:-"CALL.*racefuncenter.*"
func RaceMightPanic(a []int, i, j, k, s int) {
var b [4]int
_ = b[i] // panicIndex
_ = a[i:j] // panicSlice
_ = a[i:j:k] // also panicSlice
_ = i << s // panicShift
_ = i / j // panicDivide
}
...@@ -98,3 +98,14 @@ func check_asmout(a, b int) int { ...@@ -98,3 +98,14 @@ func check_asmout(a, b int) int {
// arm:`.*b\+4\(FP\)` // arm:`.*b\+4\(FP\)`
return b return b
} }
// Check that simple functions get promoted to nosplit, even when
// they might panic in various ways. See issue 31219.
// amd64:"TEXT\t.*NOSPLIT.*"
func MightPanic(a []int, i, j, k, s int) {
_ = a[i] // panicIndex
_ = a[i:j] // panicSlice
_ = a[i:j:k] // also panicSlice
_ = i << s // panicShift
_ = i / j // panicDivide
}
...@@ -660,6 +660,9 @@ func (t *test) run() { ...@@ -660,6 +660,9 @@ func (t *test) run() {
cmdline = append(cmdline, long) cmdline = append(cmdline, long)
cmd := exec.Command(goTool(), cmdline...) cmd := exec.Command(goTool(), cmdline...)
cmd.Env = append(os.Environ(), env.Environ()...) cmd.Env = append(os.Environ(), env.Environ()...)
if len(flags) > 0 && flags[0] == "-race" {
cmd.Env = append(cmd.Env, "CGO_ENABLED=1")
}
var buf bytes.Buffer var buf bytes.Buffer
cmd.Stdout, cmd.Stderr = &buf, &buf cmd.Stdout, cmd.Stderr = &buf, &buf
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment