diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2021-09-22 15:56:58 -0700 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2021-09-23 00:14:22 +0000 |
| commit | 93453233bd00cc641d2f959f1faf236e0094c2bf (patch) | |
| tree | a2d8297c3b0e47f2614456d671a2a36e14439354 /src | |
| parent | ee69b09424f611d02d4b0f0da3eff875e075438f (diff) | |
| download | go-93453233bd00cc641d2f959f1faf236e0094c2bf.tar.xz | |
cmd/compile: fix unsafe.Add with small-size offsets operands
Like other builtin functions, unsafe.Add's len operand is allowed to
be variable sized. However, unlike other builtins, it doesn't get
lowered to a runtime function call, so we never end up coercing it to
a specific type. As a result, we could end up constructing an OpAddPtr
value but with a less-than-ptr-sized addend operand.
This CL fixes this by always coercing the second operand to uintptr
during SSA construction.
Theoretically, we could do this during walk instead, but the frontend
doesn't allow converting negative constants to uintptr.
Fixes #48536.
Change-Id: Ib0619ea79df58b256b250fec967a6d3c8afea631
Reviewed-on: https://go-review.googlesource.com/c/go/+/351592
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/ssagen/ssa.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/ssagen/ssa.go b/src/cmd/compile/internal/ssagen/ssa.go index 82d232f940..9746fbd316 100644 --- a/src/cmd/compile/internal/ssagen/ssa.go +++ b/src/cmd/compile/internal/ssagen/ssa.go @@ -3206,6 +3206,11 @@ func (s *state) exprCheckPtr(n ir.Node, checkPtrOK bool) *ssa.Value { n := n.(*ir.BinaryExpr) ptr := s.expr(n.X) len := s.expr(n.Y) + + // Force len to uintptr to prevent misuse of garbage bits in the + // upper part of the register (#48536). + len = s.conv(n, len, len.Type, types.Types[types.TUINTPTR]) + return s.newValue2(ssa.OpAddPtr, n.Type(), ptr, len) default: |
