1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:21:37 -07:00

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 <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2017-06-04 12:11:19 +09:00 committed by Ian Lance Taylor
parent e25fdb968c
commit 289a8719ce
3 changed files with 35 additions and 1 deletions

View 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) }

View File

@ -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)
}
}

View 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)