summaryrefslogtreecommitdiffstats
path: root/src/cmd/cgo/internal/testgodefs/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/cgo/internal/testgodefs/testdata')
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/anonunion.go26
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/bitfields.go31
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/fieldtypedef.go18
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/issue37479.go33
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/issue37621.go23
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/issue38649.go15
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/issue39534.go12
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/issue48396.go18
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/issue8478.go20
-rw-r--r--src/cmd/cgo/internal/testgodefs/testdata/main.go57
10 files changed, 253 insertions, 0 deletions
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/anonunion.go b/src/cmd/cgo/internal/testgodefs/testdata/anonunion.go
new file mode 100644
index 0000000..2c86c5c
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/anonunion.go
@@ -0,0 +1,26 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+// This file tests that when cgo -godefs sees a struct with a field
+// that is an anonymous union, the first field in the union is
+// promoted to become a field of the struct. See issue 6677 for
+// background.
+
+/*
+typedef struct {
+ union {
+ long l;
+ int c;
+ };
+} t;
+*/
+import "C"
+
+// Input for cgo -godefs.
+
+type T C.t
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/bitfields.go b/src/cmd/cgo/internal/testgodefs/testdata/bitfields.go
new file mode 100644
index 0000000..431ffc0
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/bitfields.go
@@ -0,0 +1,31 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+// This file tests that we don't generate an incorrect field location
+// for a bitfield that appears aligned.
+
+/*
+struct bitfields {
+ unsigned int B1 : 5;
+ unsigned int B2 : 1;
+ unsigned int B3 : 1;
+ unsigned int B4 : 1;
+ unsigned int Short1 : 16; // misaligned on 8 bit boundary
+ unsigned int B5 : 1;
+ unsigned int B6 : 1;
+ unsigned int B7 : 1;
+ unsigned int B8 : 1;
+ unsigned int B9 : 1;
+ unsigned int B10 : 3;
+ unsigned int Short2 : 16; // alignment is OK
+ unsigned int Short3 : 16; // alignment is OK
+};
+*/
+import "C"
+
+type bitfields C.struct_bitfields
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/fieldtypedef.go b/src/cmd/cgo/internal/testgodefs/testdata/fieldtypedef.go
new file mode 100644
index 0000000..b0c5074
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/fieldtypedef.go
@@ -0,0 +1,18 @@
+// Copyright 2018 The Go Authors. All rights reserve d.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+/*
+struct S1 { int f1; };
+struct S2 { struct S1 s1; };
+typedef struct S1 S1Type;
+typedef struct S2 S2Type;
+*/
+import "C"
+
+type S1 C.S1Type
+type S2 C.S2Type
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/issue37479.go b/src/cmd/cgo/internal/testgodefs/testdata/issue37479.go
new file mode 100644
index 0000000..d545310
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/issue37479.go
@@ -0,0 +1,33 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+/*
+typedef struct A A;
+
+typedef struct {
+ struct A *next;
+ struct A **prev;
+} N;
+
+struct A
+{
+ N n;
+};
+
+typedef struct B
+{
+ A* a;
+} B;
+*/
+import "C"
+
+type N C.N
+
+type A C.A
+
+type B C.B
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/issue37621.go b/src/cmd/cgo/internal/testgodefs/testdata/issue37621.go
new file mode 100644
index 0000000..655e8ae
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/issue37621.go
@@ -0,0 +1,23 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+/*
+struct tt {
+ long long a;
+ long long b;
+};
+
+struct s {
+ struct tt ts[3];
+};
+*/
+import "C"
+
+type TT C.struct_tt
+
+type S C.struct_s
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/issue38649.go b/src/cmd/cgo/internal/testgodefs/testdata/issue38649.go
new file mode 100644
index 0000000..78b5f78
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/issue38649.go
@@ -0,0 +1,15 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+/*
+struct Issue38649 { int x; };
+#define issue38649 struct Issue38649
+*/
+import "C"
+
+type issue38649 C.issue38649
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/issue39534.go b/src/cmd/cgo/internal/testgodefs/testdata/issue39534.go
new file mode 100644
index 0000000..af730e9
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/issue39534.go
@@ -0,0 +1,12 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+// enum { ENUMVAL = 0x1 };
+import "C"
+
+const ENUMVAL = C.ENUMVAL
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/issue48396.go b/src/cmd/cgo/internal/testgodefs/testdata/issue48396.go
new file mode 100644
index 0000000..81dd2fe
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/issue48396.go
@@ -0,0 +1,18 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+/*
+// from <linux/kcm.h>
+struct issue48396 {
+ int fd;
+ int bpf_fd;
+};
+*/
+import "C"
+
+type Issue48396 C.struct_issue48396
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/issue8478.go b/src/cmd/cgo/internal/testgodefs/testdata/issue8478.go
new file mode 100644
index 0000000..f4ef164
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/issue8478.go
@@ -0,0 +1,20 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build ignore
+
+package main
+
+// Issue 8478. Test that void* is consistently mapped to *byte.
+
+/*
+typedef struct {
+ void *p;
+ void **q;
+ void ***r;
+} s;
+*/
+import "C"
+
+type Issue8478 C.s
diff --git a/src/cmd/cgo/internal/testgodefs/testdata/main.go b/src/cmd/cgo/internal/testgodefs/testdata/main.go
new file mode 100644
index 0000000..5c670f3
--- /dev/null
+++ b/src/cmd/cgo/internal/testgodefs/testdata/main.go
@@ -0,0 +1,57 @@
+// Copyright 2014 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+)
+
+// Test that the struct field in anonunion.go was promoted.
+var v1 T
+var v2 = v1.L
+
+// Test that P, Q, and R all point to byte.
+var v3 = Issue8478{P: (*byte)(nil), Q: (**byte)(nil), R: (***byte)(nil)}
+
+// Test that N, A and B are fully defined
+var v4 = N{}
+var v5 = A{}
+var v6 = B{}
+
+// Test that S is fully defined
+var v7 = S{}
+
+// Test that #define'd type is fully defined
+var _ = issue38649{X: 0}
+
+// Test that prefixes do not cause duplicate field names.
+var _ = Issue48396{Fd: 1, Bpf_fd: 2}
+
+func main() {
+ pass := true
+
+ // The Go translation of bitfields should not have any of the
+ // bitfield types. The order in which bitfields are laid out
+ // in memory is implementation defined, so we can't easily
+ // know how a bitfield should correspond to a Go type, even if
+ // it appears to be aligned correctly.
+ bitfieldType := reflect.TypeOf(bitfields{})
+ check := func(name string) {
+ _, ok := bitfieldType.FieldByName(name)
+ if ok {
+ fmt.Fprintf(os.Stderr, "found unexpected bitfields field %s\n", name)
+ pass = false
+ }
+ }
+ check("Short1")
+ check("Short2")
+ check("Short3")
+
+ if !pass {
+ os.Exit(1)
+ }
+}