From: Hiroshi Ioka Date: Sun, 4 Jun 2017 03:11:19 +0000 (+0900) Subject: cmd/cgo: unwrap typedef-chains before type checking X-Git-Tag: go1.9rc1~150 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=289a8719ce4a84cec0ed4e47037da0e82d67dcb8;p=gostls13.git cmd/cgo: unwrap typedef-chains before type checking 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/misc/cgo/test/cgo_test.go b/misc/cgo/test/cgo_test.go index f248381b14..f7cf6f613c 100644 --- a/misc/cgo/test/cgo_test.go +++ b/misc/cgo/test/cgo_test.go @@ -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 index 0000000000..e69e0e16ef --- /dev/null +++ b/misc/cgo/test/issue20129.go @@ -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) + } +} diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 766d87da7c..ff8b81354b 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -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)