diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-27 04:21:40 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-06-27 04:21:40 +0000 |
commit | 936615752a29ab245708d40782427c25e60a2114 (patch) | |
tree | f43366b59cae9e51da40272eefd1ea71bb3ea055 /libgo/misc/cgo/testgodefs | |
parent | 9913ef5866a64176bac5749080487b0c7d637d4b (diff) | |
download | gcc-936615752a29ab245708d40782427c25e60a2114.zip gcc-936615752a29ab245708d40782427c25e60a2114.tar.gz gcc-936615752a29ab245708d40782427c25e60a2114.tar.bz2 |
libgo: add misc/cgo files
Copy all the misc/cgo files from the gc toolchain into libgo/misc.
These will be used for testing purposes by later changes to the
gotools directory.
Reviewed-on: https://go-review.googlesource.com/46721
From-SVN: r249674
Diffstat (limited to 'libgo/misc/cgo/testgodefs')
-rw-r--r-- | libgo/misc/cgo/testgodefs/anonunion.go | 26 | ||||
-rw-r--r-- | libgo/misc/cgo/testgodefs/issue8478.go | 20 | ||||
-rw-r--r-- | libgo/misc/cgo/testgodefs/main.go | 15 | ||||
-rw-r--r-- | libgo/misc/cgo/testgodefs/test.bash | 22 |
4 files changed, 83 insertions, 0 deletions
diff --git a/libgo/misc/cgo/testgodefs/anonunion.go b/libgo/misc/cgo/testgodefs/anonunion.go new file mode 100644 index 0000000..18840f2 --- /dev/null +++ b/libgo/misc/cgo/testgodefs/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. +// +// +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/libgo/misc/cgo/testgodefs/issue8478.go b/libgo/misc/cgo/testgodefs/issue8478.go new file mode 100644 index 0000000..2321446 --- /dev/null +++ b/libgo/misc/cgo/testgodefs/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. +// +// +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/libgo/misc/cgo/testgodefs/main.go b/libgo/misc/cgo/testgodefs/main.go new file mode 100644 index 0000000..1ce0fd0 --- /dev/null +++ b/libgo/misc/cgo/testgodefs/main.go @@ -0,0 +1,15 @@ +// 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 + +// 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)} + +func main() { +} diff --git a/libgo/misc/cgo/testgodefs/test.bash b/libgo/misc/cgo/testgodefs/test.bash new file mode 100644 index 0000000..a82ff93 --- /dev/null +++ b/libgo/misc/cgo/testgodefs/test.bash @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# 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. + +# We are testing cgo -godefs, which translates Go files that use +# import "C" into Go files with Go definitions of types defined in the +# import "C" block. Add more tests here. +FILE_PREFIXES="anonunion issue8478" + +RM= +for FP in $FILE_PREFIXES +do + go tool cgo -godefs -srcdir . ${FP}.go > ${FP}_defs.go + RM="${RM} ${FP}_defs.go" +done + +go build . && ./testgodefs +EXIT=$? +rm -rf _obj testgodefs ${RM} +exit $EXIT |