1 // Copyright 2015 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.
5 // Issue 10303. Pointers passed to C were not marked as escaping (bug in cgo).
14 void setintstar(int *x) {
18 void setintptr(intptr x) {
22 void setvoidptr(void *x) {
26 typedef struct Struct Struct;
31 void setstruct(Struct s) {
43 func test10303(t
*testing
.T
, n
int) {
44 if runtime
.Compiler
== "gccgo" {
45 t
.Skip("gccgo permits C pointers on the stack")
48 // Run at a few different stack depths just to avoid an unlucky pass
49 // due to variables ending up on different pages.
56 var x
, y
, z
, v
, si C
.int
60 C
.setvoidptr(unsafe
.Pointer(&v
))
64 if uintptr(unsafe
.Pointer(&x
))&^0xfff == uintptr(unsafe
.Pointer(&z
))&^0xfff {
65 t
.Error("C int* argument on stack")
67 if uintptr(unsafe
.Pointer(&y
))&^0xfff == uintptr(unsafe
.Pointer(&z
))&^0xfff {
68 t
.Error("C intptr argument on stack")
70 if uintptr(unsafe
.Pointer(&v
))&^0xfff == uintptr(unsafe
.Pointer(&z
))&^0xfff {
71 t
.Error("C void* argument on stack")
73 if uintptr(unsafe
.Pointer(&si
))&^0xfff == uintptr(unsafe
.Pointer(&z
))&^0xfff {
74 t
.Error("C struct field pointer on stack")