From 4a483ce2ab493aaffc37bfb414de93d0622662fd Mon Sep 17 00:00:00 2001 From: Jess Frazelle Date: Mon, 17 Jul 2017 23:41:40 -0400 Subject: [PATCH] cmd/cgo: fix for function taking pointer typedef Fixes #19832 Change-Id: I7ce39c2c435d4716d8a42ac6784b4c87874c0e13 Reviewed-on: https://go-review.googlesource.com/49490 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Russ Cox --- misc/cgo/test/issue19832.go | 16 ++++++++++++++++ src/cmd/cgo/gcc.go | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 misc/cgo/test/issue19832.go diff --git a/misc/cgo/test/issue19832.go b/misc/cgo/test/issue19832.go new file mode 100644 index 0000000000..44587770af --- /dev/null +++ b/misc/cgo/test/issue19832.go @@ -0,0 +1,16 @@ +// Copyright 2015 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. + +// Issue 19832. Functions taking a pointer typedef were being expanded and triggering a compiler error. + +package cgotest + +// typedef struct { int i; } *PS; +// void T19832(PS p) {} +import "C" +import "testing" + +func test19832(t *testing.T) { + C.T19832(nil) +} diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 77a59c6633..a59892ef00 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -2227,6 +2227,12 @@ func (c *typeConv) FuncArg(dtype dwarf.Type, pos token.Pos) *Type { break } + // If we already know the typedef for t just use that. + // See issue 19832. + if def := typedef[t.Go.(*ast.Ident).Name]; def != nil { + break + } + t = c.Type(ptr, pos) if t == nil { return nil -- 2.48.1