1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // A C function returning a value on the Go stack could leave the Go
8 // stack marked as uninitialized, potentially causing a later error
9 // when the stack is used for something else. Issue 26209.
12 #cgo LDFLAGS: -fsanitize=memory
13 #cgo CPPFLAGS: -fsanitize=memory
26 p = (S *)(malloc(sizeof(S)));
33 // allocateStack extends the stack so that stack copying doesn't
34 // confuse the msan data structures.
36 func allocateStack(i int) int {
40 return allocateStack(i - 1)
43 // F1 marks a chunk of stack as uninitialized.
44 // C.f returns an uninitialized struct on the stack, so msan will mark
45 // the stack as uninitialized.
49 return uintptr(s.a[0])
52 // F2 allocates a struct on the stack and converts it to an empty interface,
53 // which will call msanread and see that the data appears uninitialized.
55 func F2() interface{} {
59 func poisonStack(i int) int {
64 r := poisonStack(i - 1)