]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: unwrap typedef-chains before type checking
authorHiroshi Ioka <hirochachacha@gmail.com>
Sun, 4 Jun 2017 03:11:19 +0000 (12:11 +0900)
committerIan Lance Taylor <iant@golang.org>
Tue, 27 Jun 2017 23:02:34 +0000 (23:02 +0000)
clang can emit some dwarf.VoidType which are wrapped by multiple
dwarf.TypedefType. We need to unwrap those before further processing.

Fixes #20129

Change-Id: I671ce6aef2dc7b55f1a02aec5f9789ac1b369643
Reviewed-on: https://go-review.googlesource.com/44772
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/test/cgo_test.go
misc/cgo/test/issue20129.go [new file with mode: 0644]
src/cmd/cgo/gcc.go

index f248381b148f2eef79a8b8731b6471df651bff60..f7cf6f613c4c2b09f1cc7b6fbdd8f0ded94761a5 100644 (file)
@@ -79,5 +79,6 @@ func Test18126(t *testing.T)                 { test18126(t) }
 func Test20369(t *testing.T)                 { test20369(t) }
 func Test18720(t *testing.T)                 { test18720(t) }
 func Test20266(t *testing.T)                 { test20266(t) }
+func Test20129(t *testing.T)                 { test20129(t) }
 
 func BenchmarkCgoCall(b *testing.B) { benchCgoCall(b) }
diff --git a/misc/cgo/test/issue20129.go b/misc/cgo/test/issue20129.go
new file mode 100644 (file)
index 0000000..e69e0e1
--- /dev/null
@@ -0,0 +1,33 @@
+// 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 cgotest
+
+/*
+int issue20129 = 0;
+typedef void issue20129Void;
+issue20129Void issue20129Foo() {
+       issue20129 = 1;
+}
+typedef issue20129Void issue20129Void2;
+issue20129Void2 issue20129Bar() {
+       issue20129 = 2;
+}
+*/
+import "C"
+import "testing"
+
+func test20129(t *testing.T) {
+       if C.issue20129 != 0 {
+               t.Fatal("test is broken")
+       }
+       C.issue20129Foo()
+       if C.issue20129 != 1 {
+               t.Errorf("got %v but expected %v", C.issue20129, 1)
+       }
+       C.issue20129Bar()
+       if C.issue20129 != 2 {
+               t.Errorf("got %v but expected %v", C.issue20129, 2)
+       }
+}
index 766d87da7cfc84cdd27b03632e229983687e0fd4..ff8b81354b561b3d7a8ea2ab3940e16d65f7f902 100644 (file)
@@ -2286,7 +2286,7 @@ func (c *typeConv) FuncType(dtype *dwarf.FuncType, pos token.Pos) *FuncType {
        }
        var r *Type
        var gr []*ast.Field
-       if _, ok := dtype.ReturnType.(*dwarf.VoidType); ok {
+       if _, ok := base(dtype.ReturnType).(*dwarf.VoidType); ok {
                gr = []*ast.Field{{Type: c.goVoid}}
        } else if dtype.ReturnType != nil {
                r = c.Type(unqual(dtype.ReturnType), pos)