aboutsummaryrefslogtreecommitdiff
path: root/misc/cgo/errors/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo/errors/testdata')
-rw-r--r--misc/cgo/errors/testdata/err1.go18
-rw-r--r--misc/cgo/errors/testdata/err2.go13
-rw-r--r--misc/cgo/errors/testdata/err3.go18
-rw-r--r--misc/cgo/errors/testdata/err4.go15
-rw-r--r--misc/cgo/errors/testdata/issue11097a.go15
-rw-r--r--misc/cgo/errors/testdata/issue11097b.go15
-rw-r--r--misc/cgo/errors/testdata/issue13129.go14
-rw-r--r--misc/cgo/errors/testdata/issue13423.go12
-rw-r--r--misc/cgo/errors/testdata/issue13467.go15
-rw-r--r--misc/cgo/errors/testdata/issue13635.go24
-rw-r--r--misc/cgo/errors/testdata/issue13830.go26
-rw-r--r--misc/cgo/errors/testdata/issue14669.go23
-rw-r--r--misc/cgo/errors/testdata/issue16116.go12
-rw-r--r--misc/cgo/errors/testdata/issue16591.go17
-rw-r--r--misc/cgo/errors/testdata/issue18452.go18
-rw-r--r--misc/cgo/errors/testdata/issue18889.go7
-rw-r--r--misc/cgo/errors/testdata/issue26745.go17
-rw-r--r--misc/cgo/errors/testdata/issue28069.go26
-rw-r--r--misc/cgo/errors/testdata/issue28721.go29
-rw-r--r--misc/cgo/errors/testdata/issue7757.go14
-rw-r--r--misc/cgo/errors/testdata/issue8442.go17
-rw-r--r--misc/cgo/errors/testdata/long_double_size.go16
-rw-r--r--misc/cgo/errors/testdata/malloc.go34
23 files changed, 415 insertions, 0 deletions
diff --git a/misc/cgo/errors/testdata/err1.go b/misc/cgo/errors/testdata/err1.go
new file mode 100644
index 0000000000..2c232cf58a
--- /dev/null
+++ b/misc/cgo/errors/testdata/err1.go
@@ -0,0 +1,18 @@
+// Copyright 2013 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
+
+/*
+#cgo LDFLAGS: -L/nonexist
+
+void test() {
+ xxx; // ERROR HERE
+}
+*/
+import "C"
+
+func main() {
+ C.test()
+}
diff --git a/misc/cgo/errors/testdata/err2.go b/misc/cgo/errors/testdata/err2.go
new file mode 100644
index 0000000000..3ab410bbaa
--- /dev/null
+++ b/misc/cgo/errors/testdata/err2.go
@@ -0,0 +1,13 @@
+// Copyright 2013 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 "C"
+
+func main() {
+ s := ""
+ _ = s
+ C.malloc(s) // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/err3.go b/misc/cgo/errors/testdata/err3.go
new file mode 100644
index 0000000000..609e1a0b74
--- /dev/null
+++ b/misc/cgo/errors/testdata/err3.go
@@ -0,0 +1,18 @@
+// 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
+
+/*
+typedef struct foo foo_t;
+typedef struct bar bar_t;
+
+foo_t *foop;
+*/
+import "C"
+
+func main() {
+ x := (*C.bar_t)(nil)
+ C.foop = x // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/err4.go b/misc/cgo/errors/testdata/err4.go
new file mode 100644
index 0000000000..8e5f78e987
--- /dev/null
+++ b/misc/cgo/errors/testdata/err4.go
@@ -0,0 +1,15 @@
+// Copyright 2017 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
+
+/*
+long double x = 0;
+*/
+import "C"
+
+func main() {
+ _ = C.x // ERROR HERE
+ _ = C.x
+}
diff --git a/misc/cgo/errors/testdata/issue11097a.go b/misc/cgo/errors/testdata/issue11097a.go
new file mode 100644
index 0000000000..028d10ce5c
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue11097a.go
@@ -0,0 +1,15 @@
+// Copyright 2015 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
+
+/*
+//enum test { foo, bar };
+*/
+import "C"
+
+func main() {
+ var a = C.enum_test(1) // ERROR HERE
+ _ = a
+}
diff --git a/misc/cgo/errors/testdata/issue11097b.go b/misc/cgo/errors/testdata/issue11097b.go
new file mode 100644
index 0000000000..b00f24fc10
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue11097b.go
@@ -0,0 +1,15 @@
+// Copyright 2015 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
+
+/*
+//enum test { foo, bar };
+*/
+import "C"
+
+func main() {
+ p := new(C.enum_test) // ERROR HERE
+ _ = p
+}
diff --git a/misc/cgo/errors/testdata/issue13129.go b/misc/cgo/errors/testdata/issue13129.go
new file mode 100644
index 0000000000..057bce4b82
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue13129.go
@@ -0,0 +1,14 @@
+// Copyright 2015 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.
+
+// issue 13129: used to output error about C.unsignedshort with CC=clang
+
+package main
+
+import "C"
+
+func main() {
+ var x C.ushort
+ x = int(0) // ERROR HERE: C\.ushort
+}
diff --git a/misc/cgo/errors/testdata/issue13423.go b/misc/cgo/errors/testdata/issue13423.go
new file mode 100644
index 0000000000..fc19157237
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue13423.go
@@ -0,0 +1,12 @@
+// Copyright 2015 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
+
+// #include <stdio.h>
+import "C"
+
+func main() {
+ _ = C.fopen() // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue13467.go b/misc/cgo/errors/testdata/issue13467.go
new file mode 100644
index 0000000000..e061880dda
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue13467.go
@@ -0,0 +1,15 @@
+// Copyright 2017 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 p
+
+/*
+static int transform(int x) { return x; }
+*/
+import "C"
+
+func F() {
+ var x rune = '✈'
+ var _ rune = C.transform(x) // ERROR HERE: C\.int
+}
diff --git a/misc/cgo/errors/testdata/issue13635.go b/misc/cgo/errors/testdata/issue13635.go
new file mode 100644
index 0000000000..3f38f5df4b
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue13635.go
@@ -0,0 +1,24 @@
+// Copyright 2015 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.
+
+// issue 13635: used to output error about C.unsignedchar.
+// This test tests all such types.
+
+package pkg
+
+import "C"
+
+func main() {
+ var (
+ _ C.uchar = "uc" // ERROR HERE: C\.uchar
+ _ C.schar = "sc" // ERROR HERE: C\.schar
+ _ C.ushort = "us" // ERROR HERE: C\.ushort
+ _ C.uint = "ui" // ERROR HERE: C\.uint
+ _ C.ulong = "ul" // ERROR HERE: C\.ulong
+ _ C.longlong = "ll" // ERROR HERE: C\.longlong
+ _ C.ulonglong = "ull" // ERROR HERE: C\.ulonglong
+ _ C.complexfloat = "cf" // ERROR HERE: C\.complexfloat
+ _ C.complexdouble = "cd" // ERROR HERE: C\.complexdouble
+ )
+}
diff --git a/misc/cgo/errors/testdata/issue13830.go b/misc/cgo/errors/testdata/issue13830.go
new file mode 100644
index 0000000000..ac20c82b81
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue13830.go
@@ -0,0 +1,26 @@
+// Copyright 2016 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.
+
+// cgo converts C void* to Go unsafe.Pointer, so despite appearances C
+// void** is Go *unsafe.Pointer. This test verifies that we detect the
+// problem at build time.
+
+package main
+
+// typedef void v;
+// void F(v** p) {}
+import "C"
+
+import "unsafe"
+
+type v [0]byte
+
+func f(p **v) {
+ C.F((**C.v)(unsafe.Pointer(p))) // ERROR HERE
+}
+
+func main() {
+ var p *v
+ f(&p)
+}
diff --git a/misc/cgo/errors/testdata/issue14669.go b/misc/cgo/errors/testdata/issue14669.go
new file mode 100644
index 0000000000..04d2bcb631
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue14669.go
@@ -0,0 +1,23 @@
+// Copyright 2016 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.
+
+// Issue 14669: test that fails when build with CGO_CFLAGS selecting
+// optimization.
+
+package p
+
+/*
+const int E = 1;
+
+typedef struct s {
+ int c;
+} s;
+*/
+import "C"
+
+func F() {
+ _ = C.s{
+ c: C.E,
+ }
+}
diff --git a/misc/cgo/errors/testdata/issue16116.go b/misc/cgo/errors/testdata/issue16116.go
new file mode 100644
index 0000000000..1e01cab844
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue16116.go
@@ -0,0 +1,12 @@
+// Copyright 2016 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
+
+// void f(void *p, int x) {}
+import "C"
+
+func main() {
+ _ = C.f(1) // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue16591.go b/misc/cgo/errors/testdata/issue16591.go
new file mode 100644
index 0000000000..10eb8403cf
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue16591.go
@@ -0,0 +1,17 @@
+// Copyright 2016 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.
+
+// Issue 16591: Test that we detect an invalid call that was being
+// hidden by a type conversion inserted by cgo checking.
+
+package p
+
+// void f(int** p) { }
+import "C"
+
+type x *C.int
+
+func F(p *x) {
+ C.f(p) // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue18452.go b/misc/cgo/errors/testdata/issue18452.go
new file mode 100644
index 0000000000..0386d76892
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue18452.go
@@ -0,0 +1,18 @@
+// Copyright 2017 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.
+
+// Issue 18452: show pos info in undefined name errors
+
+package p
+
+import (
+ "C"
+ "fmt"
+)
+
+func a() {
+ fmt.Println("Hello, world!")
+ C.function_that_does_not_exist() // ERROR HERE
+ C.pi // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue18889.go b/misc/cgo/errors/testdata/issue18889.go
new file mode 100644
index 0000000000..bba6b8f9bb
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue18889.go
@@ -0,0 +1,7 @@
+package main
+
+import "C"
+
+func main() {
+ _ = C.malloc // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue26745.go b/misc/cgo/errors/testdata/issue26745.go
new file mode 100644
index 0000000000..0e224538db
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue26745.go
@@ -0,0 +1,17 @@
+// Copyright 2018 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
+
+// int a;
+// void CF(int i) {}
+import "C"
+
+func F1(i int) int {
+ return C.a + 1 // ERROR HERE: :13
+}
+
+func F2(i int) {
+ C.CF(i) // ERROR HERE: :6
+}
diff --git a/misc/cgo/errors/testdata/issue28069.go b/misc/cgo/errors/testdata/issue28069.go
new file mode 100644
index 0000000000..e19a3b45bd
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue28069.go
@@ -0,0 +1,26 @@
+// Copyright 2018 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.
+
+// Test that the error message for an unrepresentable typedef in a
+// union appears on the right line. This test is only run if the size
+// of long double is larger than 64.
+
+package main
+
+/*
+typedef long double Float128;
+
+typedef struct SV {
+ union {
+ Float128 float128;
+ } value;
+} SV;
+*/
+import "C"
+
+type ts struct {
+ tv *C.SV // ERROR HERE
+}
+
+func main() {}
diff --git a/misc/cgo/errors/testdata/issue28721.go b/misc/cgo/errors/testdata/issue28721.go
new file mode 100644
index 0000000000..0eb2a9271c
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue28721.go
@@ -0,0 +1,29 @@
+// Copyright 2018 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.
+
+// cgo should reject the use of mangled C names.
+
+package main
+
+/*
+typedef struct a {
+ int i;
+} a;
+void fn(void) {}
+*/
+import "C"
+
+type B _Ctype_struct_a // ERROR HERE
+
+var a _Ctype_struct_a // ERROR HERE
+
+type A struct {
+ a *_Ctype_struct_a // ERROR HERE
+}
+
+var notExist _Ctype_NotExist // ERROR HERE
+
+func main() {
+ _Cfunc_fn() // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue7757.go b/misc/cgo/errors/testdata/issue7757.go
new file mode 100644
index 0000000000..0426e9fb7e
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue7757.go
@@ -0,0 +1,14 @@
+// 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
+
+/*
+void foo() {}
+*/
+import "C"
+
+func main() {
+ C.foo = C.foo // ERROR HERE
+}
diff --git a/misc/cgo/errors/testdata/issue8442.go b/misc/cgo/errors/testdata/issue8442.go
new file mode 100644
index 0000000000..60477ad345
--- /dev/null
+++ b/misc/cgo/errors/testdata/issue8442.go
@@ -0,0 +1,17 @@
+// 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
+
+// Issue 8442. Cgo output unhelpful error messages for
+// invalid C preambles.
+
+/*
+void issue8442foo(UNDEF*); // ERROR HERE
+*/
+import "C"
+
+func main() {
+ C.issue8442foo(nil)
+}
diff --git a/misc/cgo/errors/testdata/long_double_size.go b/misc/cgo/errors/testdata/long_double_size.go
new file mode 100644
index 0000000000..8b797f886a
--- /dev/null
+++ b/misc/cgo/errors/testdata/long_double_size.go
@@ -0,0 +1,16 @@
+// Copyright 2017 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
+
+/*
+const int sizeofLongDouble = sizeof(long double);
+*/
+import "C"
+
+import "fmt"
+
+func main() {
+ fmt.Println(C.sizeofLongDouble)
+}
diff --git a/misc/cgo/errors/testdata/malloc.go b/misc/cgo/errors/testdata/malloc.go
new file mode 100644
index 0000000000..65da0208b9
--- /dev/null
+++ b/misc/cgo/errors/testdata/malloc.go
@@ -0,0 +1,34 @@
+// Copyright 2016 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.
+
+// Test that C.malloc does not return nil.
+
+package main
+
+// #include <stdlib.h>
+import "C"
+
+import (
+ "fmt"
+ "runtime"
+)
+
+func main() {
+ var size C.size_t
+ size--
+
+ // The Dragonfly libc succeeds when asked to allocate
+ // 0xffffffffffffffff bytes, so pass a different value that
+ // causes it to fail.
+ if runtime.GOOS == "dragonfly" {
+ size = C.size_t(0x7fffffff << (32 * (^uintptr(0) >> 63)))
+ }
+
+ p := C.malloc(size)
+ if p == nil {
+ fmt.Println("malloc: C.malloc returned nil")
+ // Just exit normally--the test script expects this
+ // program to crash, so exiting normally indicates failure.
+ }
+}