diff options
author | Matthew Dempsky <mdempsky@google.com> | 2020-04-30 23:05:51 -0700 |
---|---|---|
committer | Matthew Dempsky <mdempsky@google.com> | 2020-05-01 18:01:28 +0000 |
commit | b565d1ec1630f6ffa50024fe14ac4ea88a2e6701 (patch) | |
tree | f6bc8d523567cb92e4b027a22301e6074b5d2086 /misc | |
parent | f00b8b45a24479836d8c148cf85fd97091290b05 (diff) | |
download | go-b565d1ec1630f6ffa50024fe14ac4ea88a2e6701.tar.gz go-b565d1ec1630f6ffa50024fe14ac4ea88a2e6701.zip |
cmd/cgo: use type aliases for #define type macros
Cgo's initial design for handling "#define foo int*" involved
rewriting "C.foo" to "*_Ctype_int" everywhere. But now that we have
type aliases, we can declare "type _Ctype_foo = *_Ctype_int" once, and
then rewrite "C.foo" to just "_Ctype_foo".
This is important for go/types's UsesCgo mode, where go/types needs to
be able to figure out a type for each C.foo identifier using only the
information written into _cgo_gotypes.go.
Fixes #38649.
Change-Id: Ia0f8c2d82df81efb1be5bc26195ea9154c0af871
Reviewed-on: https://go-review.googlesource.com/c/go/+/230037
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'misc')
-rw-r--r-- | misc/cgo/test/test.go | 8 | ||||
-rw-r--r-- | misc/cgo/testgodefs/testdata/issue38649.go | 15 | ||||
-rw-r--r-- | misc/cgo/testgodefs/testdata/main.go | 3 | ||||
-rw-r--r-- | misc/cgo/testgodefs/testgodefs_test.go | 1 |
4 files changed, 27 insertions, 0 deletions
diff --git a/misc/cgo/test/test.go b/misc/cgo/test/test.go index b0148995fe..b5009d43ce 100644 --- a/misc/cgo/test/test.go +++ b/misc/cgo/test/test.go @@ -897,6 +897,10 @@ static uint16_t issue31093F(uint16_t v) { return v; } // issue 32579 typedef struct S32579 { unsigned char data[1]; } S32579; + +// issue 38649 +// Test that #define'd type aliases work. +#define netbsd_gid unsigned int */ import "C" @@ -2192,3 +2196,7 @@ func test32579(t *testing.T) { t.Errorf("&s[0].data[0] failed: got %d, want %d", s[0].data[0], 1) } } + +// issue 38649 + +var issue38649 C.netbsd_gid = 42 diff --git a/misc/cgo/testgodefs/testdata/issue38649.go b/misc/cgo/testgodefs/testdata/issue38649.go new file mode 100644 index 0000000000..6af74d6058 --- /dev/null +++ b/misc/cgo/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. +// +// +build ignore + +package main + +/* +struct Issue38649 { int x; }; +#define issue38649 struct Issue38649 +*/ +import "C" + +type issue38649 C.issue38649 diff --git a/misc/cgo/testgodefs/testdata/main.go b/misc/cgo/testgodefs/testdata/main.go index ef45b95e65..2e1ad3376a 100644 --- a/misc/cgo/testgodefs/testdata/main.go +++ b/misc/cgo/testgodefs/testdata/main.go @@ -19,5 +19,8 @@ var v6 = B{} // Test that S is fully defined var v7 = S{} +// Test that #define'd type is fully defined +var _ = issue38649{X: 0} + func main() { } diff --git a/misc/cgo/testgodefs/testgodefs_test.go b/misc/cgo/testgodefs/testgodefs_test.go index 438d23d65c..178fff3fbc 100644 --- a/misc/cgo/testgodefs/testgodefs_test.go +++ b/misc/cgo/testgodefs/testgodefs_test.go @@ -23,6 +23,7 @@ var filePrefixes = []string{ "fieldtypedef", "issue37479", "issue37621", + "issue38649", } func TestGoDefs(t *testing.T) { |