Source file test/fixedbugs/splitload_pointer_compare.go

     1  // run
     2  
     3  // Copyright 2026 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  // splitload rewrites must preserve pointer-typed loads so
     8  // spilled values remain visible to stack maps across stack growth.
     9  
    10  package main
    11  
    12  type splitLoadObj struct{ x int }
    13  
    14  var sink byte
    15  
    16  //go:noinline
    17  func splitLoadGrow(n int) {
    18  	var buf [2048]byte
    19  	buf[n&2047] = byte(n)
    20  	if n > 0 {
    21  		splitLoadGrow(n - 1)
    22  	}
    23  	sink = buf[n&2047]
    24  }
    25  
    26  //go:noinline
    27  func splitLoadPointerCompare(pp **splitLoadObj, q *splitLoadObj, a, b, m int) int {
    28  	cond := q == *pp
    29  	x := a
    30  	if cond {
    31  		x = b
    32  	}
    33  	z := x & m
    34  	splitLoadGrow(1000)
    35  	if cond {
    36  		return z
    37  	}
    38  	return x
    39  }
    40  
    41  func main() {
    42  	var obj splitLoadObj
    43  	slot := &obj
    44  	if got := splitLoadPointerCompare(&slot, &obj, 10, 6, 1); got != 0 {
    45  		println("splitLoadPointerCompare(...) =", got, "want 0")
    46  		panic("FAIL")
    47  	}
    48  }
    49  

View as plain text