]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: ensure pointer arithmetic happens after the nil check
authorKeith Randall <khr@golang.org>
Wed, 25 Oct 2023 20:35:13 +0000 (13:35 -0700)
committerKeith Randall <khr@golang.org>
Tue, 31 Oct 2023 20:45:54 +0000 (20:45 +0000)
commit962ccbef91057f91518443b648e02fc3afe8c764
tree41430edab6785e326b74e269bb3044df51260db4
parent43b57b85160f310622130e9c8653dde599d839cc
cmd/compile: ensure pointer arithmetic happens after the nil check

Have nil checks return a pointer that is known non-nil. Users of
that pointer can use the result, ensuring that they are ordered
after the nil check itself.

The order dependence goes away after scheduling, when we've fixed
an order. At that point we move uses back to the original pointer
so it doesn't change regalloc any.

This prevents pointer arithmetic on nil from being spilled to the
stack and then observed by a stack scan.

Fixes #63657

Change-Id: I1a5fa4f2e6d9000d672792b4f90dfc1b7b67f6ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/537775
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@google.com>
15 files changed:
src/cmd/compile/internal/ssa/_gen/generic.rules
src/cmd/compile/internal/ssa/_gen/genericOps.go
src/cmd/compile/internal/ssa/check.go
src/cmd/compile/internal/ssa/deadcode.go
src/cmd/compile/internal/ssa/deadstore.go
src/cmd/compile/internal/ssa/fuse.go
src/cmd/compile/internal/ssa/fuse_test.go
src/cmd/compile/internal/ssa/nilcheck.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssa/rewrite.go
src/cmd/compile/internal/ssa/rewritegeneric.go
src/cmd/compile/internal/ssa/schedule.go
src/cmd/compile/internal/ssa/value.go
src/cmd/compile/internal/ssagen/ssa.go
test/fixedbugs/issue63657.go [new file with mode: 0644]