aboutsummaryrefslogtreecommitdiff
path: root/src/internal/godebug
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2023-12-14 14:20:12 -0500
committerDavid Chase <drchase@google.com>2023-12-15 20:30:44 +0000
commit3313bbb4055f38f53cd43c6c5782a229f445f230 (patch)
treedc21ea7c327d01b9c34a1509c1ca06f26bcd4c43 /src/internal/godebug
parentb60bf8f8e131b026eb2691e736d3df9dce852297 (diff)
downloadgo-3313bbb4055f38f53cd43c6c5782a229f445f230.tar.xz
runtime: add race annotations in IncNonDefault
Also use CompareAndSwap to make the code actually less racy. Added a test which will be meaningful when run under the race detector (tested it -race with broken fix in runtime, it failed). Fixes #64649 Change-Id: I5972e08901d1adc8ba74858edad7eba91be1b0ce Reviewed-on: https://go-review.googlesource.com/c/go/+/549796 Run-TryBot: David Chase <drchase@google.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/internal/godebug')
-rw-r--r--src/internal/godebug/godebug_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/internal/godebug/godebug_test.go b/src/internal/godebug/godebug_test.go
index ed8e93d453..1ed0a365ab 100644
--- a/src/internal/godebug/godebug_test.go
+++ b/src/internal/godebug/godebug_test.go
@@ -7,6 +7,7 @@ package godebug_test
import (
"fmt"
. "internal/godebug"
+ "internal/race"
"internal/testenv"
"os"
"os/exec"
@@ -70,6 +71,36 @@ func TestMetrics(t *testing.T) {
}
}
+// TestPanicNilRace checks for a race in the runtime caused by use of runtime
+// atomics (not visible to usual race detection) to install the counter for
+// non-default panic(nil) semantics. For #64649.
+func TestPanicNilRace(t *testing.T) {
+ if !race.Enabled {
+ t.Skip("Skipping test intended for use with -race.")
+ }
+ if os.Getenv("GODEBUG") != "panicnil=1" {
+ cmd := testenv.CleanCmdEnv(testenv.Command(t, os.Args[0], "-test.run=^TestPanicNilRace$", "-test.v", "-test.parallel=2", "-test.count=1"))
+ cmd.Env = append(cmd.Env, "GODEBUG=panicnil=1")
+ out, err := cmd.CombinedOutput()
+ t.Logf("output:\n%s", out)
+
+ if err != nil {
+ t.Errorf("Was not expecting a crash")
+ }
+ return
+ }
+
+ test := func(t *testing.T) {
+ t.Parallel()
+ defer func() {
+ recover()
+ }()
+ panic(nil)
+ }
+ t.Run("One", test)
+ t.Run("Two", test)
+}
+
func TestCmdBisect(t *testing.T) {
testenv.MustHaveGoBuild(t)
out, err := exec.Command("go", "run", "cmd/vendor/golang.org/x/tools/cmd/bisect", "GODEBUG=buggy=1#PATTERN", os.Args[0], "-test.run=^TestBisectTestCase$").CombinedOutput()