diff options
author | Cherry Mui <cherryyz@google.com> | 2022-02-14 12:43:27 -0500 |
---|---|---|
committer | Dmitri Shuralyov <dmitshur@golang.org> | 2022-02-18 00:51:21 +0000 |
commit | 7d8fa657893f93dd04071bb164166d12fbdeb8a5 (patch) | |
tree | f0df8ec08bce5a45a09aebb6e2d81bf9653a7927 /test | |
parent | 1ba25fa28871cd3862f8d539155a60e004b42d56 (diff) | |
download | go-7d8fa657893f93dd04071bb164166d12fbdeb8a5.tar.gz go-7d8fa657893f93dd04071bb164166d12fbdeb8a5.zip |
[release-branch.go1.17] 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.
Updates #51101.
Fixes #51199.
Change-Id: I7e73c2155c36ff403c032981a9aa9cccbfdf0f64
Reviewed-on: https://go-review.googlesource.com/c/go/+/385655
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit 1ed30ca537a05b887f8479027b6363a03f957610)
Reviewed-on: https://go-review.googlesource.com/c/go/+/386474
Diffstat (limited to 'test')
-rw-r--r-- | test/fixedbugs/issue51101.go | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/fixedbugs/issue51101.go b/test/fixedbugs/issue51101.go new file mode 100644 index 0000000000..a390e50da4 --- /dev/null +++ b/test/fixedbugs/issue51101.go @@ -0,0 +1,36 @@ +// run + +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 51101: on RISCV64, difference of two pointers +// was marked as pointer and crashes GC. + +package main + +var a, b int + +func main() { + F(&b, &a) +} + +//go:noinline +func F(a, b *int) bool { + x := a == b + G(x) + y := a != b + return y +} + +//go:noinline +func G(bool) { + grow([1000]int{20}) +} + +func grow(x [1000]int) { + if x[0] != 0 { + x[0]-- + grow(x) + } +} |