]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.20] cmd/compile: don't assume pointer of a slice is non-nil
authorKeith Randall <khr@golang.org>
Tue, 28 Mar 2023 17:19:21 +0000 (10:19 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Wed, 29 Mar 2023 19:07:23 +0000 (19:07 +0000)
commit8dce4ca8dfd4892e2f5bdf0a1224b9efe0dca89f
tree88fe27bf38433c05e290d3cfbdbd370aa0086973
parent94c02a3cc481e4b73ce275ba6e50c286d4c492ff
[release-branch.go1.20] cmd/compile: don't assume pointer of a slice is non-nil

unsafe.SliceData can return pointers which are nil. That function gets
lowered to the SSA OpSlicePtr, which the compiler assumes is non-nil.
This used to be the case as OpSlicePtr was only used in situations
where the bounds check already passed. But with unsafe.SliceData that
is no longer the case.

There are situations where we know it is nil. Use Bounded() to
indicate that.

I looked through all the uses of OSPTR and added SetBounded where it
made sense. Most OSPTR results are passed directly to runtime calls
(e.g. memmove), so even if we know they are non-nil that info isn't
helpful.

Fixes #59296

Change-Id: I437a15330db48e0082acfb1f89caf8c56723fc51
Reviewed-on: https://go-review.googlesource.com/c/go/+/479896
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
(cherry picked from commit b899641ecea7d07c997282e985beb295c31d1097)
Reviewed-on: https://go-review.googlesource.com/c/go/+/479899
Run-TryBot: Keith Randall <khr@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
src/cmd/compile/internal/ir/node.go
src/cmd/compile/internal/ssagen/ssa.go
src/cmd/compile/internal/walk/convert.go
src/cmd/compile/internal/walk/range.go
test/fixedbugs/issue59293.go [new file with mode: 0644]