1 // Copyright 2021 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 // The -fsanitize=address option of C compier can detect stack-use-after-return bugs.
8 // In the following program, the local variable 'local' was moved to heap by the Go
9 // compiler because foo() is returning the reference to 'local', and return stack of
10 // foo() will be invalid. Thus for main() to use the reference to 'local', the 'local'
11 // must be available even after foo() has finished. Therefore, Go has no such issue.
19 fmt.Printf("ptr=%x, %v", *ptr, ptr)
25 ptr = &local // local is moved to heap.