* tree-vect-loop-manip.c (vect_do_peeling): Do not use
[official-gcc.git] / libgo / misc / cgo / test / issue10303.go
blob66e2644d06648f51dde79547b9e6ae2f802400b3
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).
7 package cgotest
9 import "runtime"
12 typedef int *intptr;
14 void setintstar(int *x) {
15 *x = 1;
18 void setintptr(intptr x) {
19 *x = 1;
22 void setvoidptr(void *x) {
23 *(int*)x = 1;
26 typedef struct Struct Struct;
27 struct Struct {
28 int *P;
31 void setstruct(Struct s) {
32 *s.P = 1;
36 import "C"
38 import (
39 "testing"
40 "unsafe"
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.
50 if n > 0 {
51 test10303(t, n-1)
53 if t.Failed() {
54 return
56 var x, y, z, v, si C.int
57 var s C.Struct
58 C.setintstar(&x)
59 C.setintptr(&y)
60 C.setvoidptr(unsafe.Pointer(&v))
61 s.P = &si
62 C.setstruct(s)
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")