mirror of
https://github.com/golang/go.git
synced 2026-06-28 11:50:35 +00:00
386 and AMD64's splitload could silently change a pointer type to an int type. Fix that. Add type preservation to the narrower widths for symmetry, even though it doesn't matter in the same way there. Change-Id: I155d136dd43989900d26f2a7f014d7300fdbb7cb Reviewed-on: https://go-review.googlesource.com/c/go/+/777820 Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org>
48 lines
923 B
Go
48 lines
923 B
Go
// run
|
|
|
|
// Copyright 2026 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.
|
|
|
|
// splitload rewrites must preserve pointer-typed loads so
|
|
// spilled values remain visible to stack maps across stack growth.
|
|
|
|
package main
|
|
|
|
type splitLoadObj struct{ x int }
|
|
|
|
var sink byte
|
|
|
|
//go:noinline
|
|
func splitLoadGrow(n int) {
|
|
var buf [2048]byte
|
|
buf[n&2047] = byte(n)
|
|
if n > 0 {
|
|
splitLoadGrow(n - 1)
|
|
}
|
|
sink = buf[n&2047]
|
|
}
|
|
|
|
//go:noinline
|
|
func splitLoadPointerCompare(pp **splitLoadObj, q *splitLoadObj, a, b, m int) int {
|
|
cond := q == *pp
|
|
x := a
|
|
if cond {
|
|
x = b
|
|
}
|
|
z := x & m
|
|
splitLoadGrow(1000)
|
|
if cond {
|
|
return z
|
|
}
|
|
return x
|
|
}
|
|
|
|
func main() {
|
|
var obj splitLoadObj
|
|
slot := &obj
|
|
if got := splitLoadPointerCompare(&slot, &obj, 10, 6, 1); got != 0 {
|
|
println("splitLoadPointerCompare(...) =", got, "want 0")
|
|
panic("FAIL")
|
|
}
|
|
}
|