aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/race/testdata
diff options
context:
space:
mode:
authorDavid Chase <drchase@google.com>2024-05-22 14:00:43 -0700
committerDavid Chase <drchase@google.com>2024-07-30 15:46:27 +0000
commitcc258e6785060345a497d44b6073c91b81e32576 (patch)
tree4bdb034ed97cf4566d521a55868c332f0df28905 /src/runtime/race/testdata
parent7b867b9bb7e7c20803a7168faaf9c87e11f88cef (diff)
downloadgo-cc258e6785060345a497d44b6073c91b81e32576.tar.xz
cmd/compile: add "deadlocals" pass to remove unused locals
This CL adds a "deadlocals" pass, which runs after inlining and before escape analysis, to prune any unneeded local variables and assignments. In particular, this helps avoid unnecessary Addrtaken markings from unreachable closures. Deadlocals is sensitive to "_ = ..." as a signal of explicit use for testing. This signal occurs only if the entire left-hand-side is "_" targets; if it is `_, ok := someInlinedFunc(args)` then the first return value is eligible for dead code elimination. Use this (`_ = x`) to fix tests broken by deadlocals elimination. Includes a test, based on one of the tests that required modification. Matthew Dempsky wrote this, changing ownership to allow rebases, commits, tweaks. Fixes #65158. Old-Change-Id: I723fb69ccd7baadaae04d415702ce6c8901eaf4e Change-Id: I1f25f4293b19527f305c18c3680b214237a7714c Reviewed-on: https://go-review.googlesource.com/c/go/+/600498 Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: David Chase <drchase@google.com> Commit-Queue: David Chase <drchase@google.com>
Diffstat (limited to 'src/runtime/race/testdata')
-rw-r--r--src/runtime/race/testdata/mop_test.go8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/runtime/race/testdata/mop_test.go b/src/runtime/race/testdata/mop_test.go
index 6b1069fcca..0d7d879d83 100644
--- a/src/runtime/race/testdata/mop_test.go
+++ b/src/runtime/race/testdata/mop_test.go
@@ -612,6 +612,8 @@ func TestNoRaceEnoughRegisters(t *testing.T) {
}
// emptyFunc should not be inlined.
+//
+//go:noinline
func emptyFunc(x int) {
if false {
fmt.Println(x)
@@ -1176,7 +1178,7 @@ func TestNoRaceHeapReallocation(t *testing.T) {
// others.
const n = 2
done := make(chan bool, n)
- empty := func(p *int) {}
+ empty := func(p *int) { _ = p }
for i := 0; i < n; i++ {
ms := i
go func() {
@@ -1417,7 +1419,7 @@ func TestRaceInterCall2(t *testing.T) {
func TestRaceFuncCall(t *testing.T) {
c := make(chan bool, 1)
- f := func(x, y int) {}
+ f := func(x, y int) { _ = y }
x, y := 0, 0
go func() {
y = 42
@@ -1804,6 +1806,7 @@ func TestRaceAsFunc2(t *testing.T) {
x := 0
go func() {
func(x int) {
+ _ = x
}(x)
c <- true
}()
@@ -1817,6 +1820,7 @@ func TestRaceAsFunc3(t *testing.T) {
x := 0
go func() {
func(x int) {
+ _ = x
mu.Lock()
}(x) // Read of x must be outside of the mutex.
mu.Unlock()