aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-08-01 12:51:19 -0700
committerIan Lance Taylor <iant@golang.org>2018-08-08 01:13:46 +0000
commitb8ae3569c8aa8cb8d569f2941939e30c3d342444 (patch)
tree0d6835141de62dcb4eb97aeb97edc00fe1e4c4f0
parent097d642de5f0d2010ce877116ff7071d3f19af58 (diff)
downloadgo-b8ae3569c8aa8cb8d569f2941939e30c3d342444.tar.gz
go-b8ae3569c8aa8cb8d569f2941939e30c3d342444.zip
[release-branch.go1.10] cmd/cgo: don't give inconsistent typedef error for cgo-defined types
The cgo tool predefines some C types such as C.uint. Don't give an error if the type that cgo defines does not match the type in a header file. Fixes #26743 Change-Id: I9ed3b4c482b558d8ffa8bf61eb3209415b7a9e3c Reviewed-on: https://go-review.googlesource.com/127356 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Keith Randall <khr@golang.org> (cherry picked from commit c29370c98ecfc7aa59f32c7a7897e50a0f6eb86b) Reviewed-on: https://go-review.googlesource.com/128396 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--misc/cgo/test/issue26743.go10
-rw-r--r--misc/cgo/test/issue26743/a.go11
-rw-r--r--misc/cgo/test/issue26743/b.go9
-rw-r--r--src/cmd/cgo/main.go4
4 files changed, 34 insertions, 0 deletions
diff --git a/misc/cgo/test/issue26743.go b/misc/cgo/test/issue26743.go
new file mode 100644
index 0000000000..35c8473a61
--- /dev/null
+++ b/misc/cgo/test/issue26743.go
@@ -0,0 +1,10 @@
+// Copyright 2018 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 26743: typedef of uint leads to inconsistent typedefs error.
+// No runtime test; just make sure it compiles.
+
+package cgotest
+
+import _ "./issue26743"
diff --git a/misc/cgo/test/issue26743/a.go b/misc/cgo/test/issue26743/a.go
new file mode 100644
index 0000000000..a3df1797b3
--- /dev/null
+++ b/misc/cgo/test/issue26743/a.go
@@ -0,0 +1,11 @@
+// Copyright 2018 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 issue26743
+
+// typedef unsigned int uint;
+// int C1(uint x) { return x; }
+import "C"
+
+var V1 = C.C1(0)
diff --git a/misc/cgo/test/issue26743/b.go b/misc/cgo/test/issue26743/b.go
new file mode 100644
index 0000000000..c5f1ae478c
--- /dev/null
+++ b/misc/cgo/test/issue26743/b.go
@@ -0,0 +1,9 @@
+// Copyright 2018 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 issue26743
+
+import "C"
+
+var V2 C.uint
diff --git a/src/cmd/cgo/main.go b/src/cmd/cgo/main.go
index 2b3e6a0a01..c3c53b35c0 100644
--- a/src/cmd/cgo/main.go
+++ b/src/cmd/cgo/main.go
@@ -394,6 +394,10 @@ func (p *Package) Record(f *File) {
p.Name[k] = v
} else if p.incompleteTypedef(v.Type) {
// Nothing to do.
+ } else if _, ok := nameToC[k]; ok {
+ // Names we predefine may appear inconsistent
+ // if some files typedef them and some don't.
+ // Issue 26743.
} else if !reflect.DeepEqual(p.Name[k], v) {
error_(token.NoPos, "inconsistent definitions for C.%s", fixGo(k))
}