Debian Codegraph @

test/codegen/zerosize.go

raw
1 // asmcheck
2
3 // Copyright 2018 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 a pointer variable and a zero-sized variable
8 // aren't allocated to the same stack slot.
9 // See issue 24993.
10
11 package codegen
12
13 func zeroSize() {
14 c := make(chan struct{})
15 // amd64:`MOVQ\t\$0, command-line-arguments\.s\+56\(SP\)`
16 var s *int
17 // force s to be a stack object, also use some (fixed) stack space
18 g(&s, 1, 2, 3, 4, 5)
19
20 // amd64:`LEAQ\tcommand-line-arguments\..*\+55\(SP\)`
21 c <- noliteral(struct{}{})
22 }
23
24 // Like zeroSize, but without hiding the zero-sized struct.
25 func zeroSize2() {
26 c := make(chan struct{})
27 // amd64:`MOVQ\t\$0, command-line-arguments\.s\+48\(SP\)`
28 var s *int
29 // force s to be a stack object, also use some (fixed) stack space
30 g(&s, 1, 2, 3, 4, 5)
31
32 // amd64:`LEAQ\tcommand-line-arguments\..*stmp_\d+\(SB\)`
33 c <- struct{}{}
34 }
35
36 //go:noinline
37 func g(**int, int, int, int, int, int) {}
38
39 // noliteral prevents the compiler from recognizing a literal value.
40 //
41 //go:noinline
42 func noliteral[T any](t T) T {
43 return t
44 }