]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: handle new panicindex/slice names in optimizations
authorKeith Randall <keithr@alum.mit.edu>
Wed, 3 Apr 2019 20:16:58 +0000 (13:16 -0700)
committerKeith Randall <khr@golang.org>
Wed, 3 Apr 2019 21:24:17 +0000 (21:24 +0000)
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: Ilya Tocar <ilya.tocar@intel.com>
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/internal/obj/x86/obj6.go
test/codegen/race.go [new file with mode: 0644]
test/codegen/stack.go
test/run.go

index 81658522634e9dcbe851fdccf3fadc4aa7ee3796..6fc504e0207daffe16355791ab7f61a051a8fce5 100644 (file)
@@ -1129,17 +1129,20 @@ func needRaceCleanup(sym interface{}, v *Value) bool {
                for _, v := range b.Values {
                        switch v.Op {
                        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.
                                // Allow calls to panic*
-                               default:
-                                       // If we encountered any call, we need to keep racefunc*,
-                                       // for accurate stacktraces.
-                                       return false
+                               s := v.Aux.(fmt.Stringer).String()
+                               switch s {
+                               case "runtime.racefuncenter", "runtime.racefuncexit",
+                                       "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:
                                // We must keep the race functions if there are any other call types.
                                return false
index eb0e88b494d25130125a7bb7f1fcf16b09cf5145..2fba397a87a2c923d7eb25bad6072f97549846df 100644 (file)
@@ -975,7 +975,13 @@ func isZeroArgRuntimeCall(s *obj.LSym) bool {
                return false
        }
        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 false
diff --git a/test/codegen/race.go b/test/codegen/race.go
new file mode 100644 (file)
index 0000000..ed6706f
--- /dev/null
@@ -0,0 +1,20 @@
+// 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
+}
index ed2c1ed95958b78d64656e0a1b040a596a87cbf4..ca3762228697f78e0ee0930f05119c1392b98ef7 100644 (file)
@@ -98,3 +98,14 @@ func check_asmout(a, b int) int {
        // arm:`.*b\+4\(FP\)`
        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
+}
index 292903f9325d7bee018fc54c261e75094bc23fa0..460d4f2d8c3c98b5f5df774e95435dd6a1b32e83 100644 (file)
@@ -660,6 +660,9 @@ func (t *test) run() {
                        cmdline = append(cmdline, long)
                        cmd := exec.Command(goTool(), cmdline...)
                        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
                        cmd.Stdout, cmd.Stderr = &buf, &buf