Skip to content

Commit 1ed30ca

Browse files
committed
cmd/compile: correct type of pointer difference on RISCV64
Pointer comparison is lowered to the following on RISCV64 (EqPtr x y) => (SEQZ (SUB <x.Type> x y)) The difference of two pointers (the SUB) should not be pointer type. Otherwise it can cause the GC to find a bad pointer. Should fix #51101. Change-Id: I7e73c2155c36ff403c032981a9aa9cccbfdf0f64 Reviewed-on: https://go-review.googlesource.com/c/go/+/385655 Trust: Cherry Mui <[email protected]> Run-TryBot: Cherry Mui <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent ada95e2 commit 1ed30ca

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

src/cmd/compile/internal/ssa/gen/RISCV64.rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@
256256
(Leq64F ...) => (FLED ...)
257257
(Leq32F ...) => (FLES ...)
258258

259-
(EqPtr x y) => (SEQZ (SUB <x.Type> x y))
259+
(EqPtr x y) => (SEQZ (SUB <typ.Uintptr> x y))
260260
(Eq64 x y) => (SEQZ (SUB <x.Type> x y))
261261
(Eq32 x y) => (SEQZ (SUB <x.Type> (ZeroExt32to64 x) (ZeroExt32to64 y)))
262262
(Eq16 x y) => (SEQZ (SUB <x.Type> (ZeroExt16to64 x) (ZeroExt16to64 y)))
263263
(Eq8 x y) => (SEQZ (SUB <x.Type> (ZeroExt8to64 x) (ZeroExt8to64 y)))
264264
(Eq64F ...) => (FEQD ...)
265265
(Eq32F ...) => (FEQS ...)
266266

267-
(NeqPtr x y) => (SNEZ (SUB <x.Type> x y))
267+
(NeqPtr x y) => (SNEZ (SUB <typ.Uintptr> x y))
268268
(Neq64 x y) => (SNEZ (SUB <x.Type> x y))
269269
(Neq32 x y) => (SNEZ (SUB <x.Type> (ZeroExt32to64 x) (ZeroExt32to64 y)))
270270
(Neq16 x y) => (SNEZ (SUB <x.Type> (ZeroExt16to64 x) (ZeroExt16to64 y)))

src/cmd/compile/internal/ssa/rewriteRISCV64.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue51101.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// run
2+
3+
// Copyright 2022 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 51101: on RISCV64, difference of two pointers
8+
// was marked as pointer and crashes GC.
9+
10+
package main
11+
12+
var a, b int
13+
14+
func main() {
15+
F(&b, &a)
16+
}
17+
18+
//go:noinline
19+
func F(a, b *int) bool {
20+
x := a == b
21+
G(x)
22+
y := a != b
23+
return y
24+
}
25+
26+
//go:noinline
27+
func G(bool) {
28+
grow([1000]int{20})
29+
}
30+
31+
func grow(x [1000]int) {
32+
if x[0] != 0 {
33+
x[0]--
34+
grow(x)
35+
}
36+
}

0 commit comments

Comments
 (0)