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.
37 func allocateStack(i int) int {
41 return allocateStack(i - 1)
44 // F1 marks a chunk of stack as uninitialized.
45 // C.f returns an uninitialized struct on the stack, so msan will mark
46 // the stack as uninitialized.
51 return uintptr(s.a[0])
54 // F2 allocates a struct on the stack and converts it to an empty interface,
55 // which will call msanread and see that the data appears uninitialized.
58 func F2() interface{} {
62 func poisonStack(i int) int {
67 r := poisonStack(i - 1)