Debian Codegraph @

test/fixedbugs/issue63657.go

raw
1 // run
2
3 // Copyright 2023 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 // Make sure address calculations don't float up before
8 // the corresponding nil check.
9
10 package main
11
12 type T struct {
13 a, b int
14 }
15
16 //go:noinline
17 func f(x *T, p *bool, n int) {
18 *p = n != 0
19 useStack(1000)
20 g(&x.b)
21 }
22
23 //go:noinline
24 func g(p *int) {
25 }
26
27 func useStack(n int) {
28 if n == 0 {
29 return
30 }
31 useStack(n - 1)
32 }
33
34 func main() {
35 mustPanic(func() {
36 var b bool
37 f(nil, &b, 3)
38 })
39 }
40
41 func mustPanic(f func()) {
42 defer func() {
43 if recover() == nil {
44 panic("expected panic, got nil")
45 }
46 }()
47 f()
48 }