aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2016-11-01 14:13:34 -0700
committerIan Lance Taylor <iant@golang.org>2016-11-01 23:06:24 +0000
commit689947d5652e51980fbfc7b350871fe2baa06a74 (patch)
tree3a42dbce9ec8f9de1167c565a99b9f740bdf02e0 /src
parent3be166dc70bf3539539bc6762aff9660c3dbf229 (diff)
downloadgo-689947d5652e51980fbfc7b350871fe2baa06a74.tar.xz
cmd/cgo: only record typedef name for pointer to struct
In a function argument, we handle a typedef for a pointer specially, using the pointer type rather than the typedef, to permit the Go calls to match the laxer type conversions permitted in C. We record the typedef so that we use that type in the C code, in case it has a special attribute. However, using the typedef is wrong when using a pointer to a basic type, because the C code may sometimes use the typedef and sometimes not, and using the typedef in all cases will cause incorrect type errors on the Go side. Fortunately we only really need to use the typedef when pointing to a struct/union/class, and in such a case confusion is unlikely. Fixes #17723. Change-Id: Id2eaeb156faeaf2e8eb9cf0b8f95b44caf8cfbd2 Reviewed-on: https://go-review.googlesource.com/32536 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/cgo/gcc.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
index 450120f83c..de87df0798 100644
--- a/src/cmd/cgo/gcc.go
+++ b/src/cmd/cgo/gcc.go
@@ -1937,9 +1937,12 @@ func (c *typeConv) FuncArg(dtype dwarf.Type, pos token.Pos) *Type {
return nil
}
- // Remember the C spelling, in case the struct
- // has __attribute__((unavailable)) on it. See issue 2888.
- t.Typedef = dt.Name
+ // For a struct/union/class, remember the C spelling,
+ // in case it has __attribute__((unavailable)).
+ // See issue 2888.
+ if isStructUnionClass(t.Go) {
+ t.Typedef = dt.Name
+ }
}
}
return t