]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.10] cmd/cgo: don't give inconsistent typedef error for cgo-define...
authorIan Lance Taylor <iant@golang.org>
Wed, 1 Aug 2018 19:51:19 +0000 (12:51 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 8 Aug 2018 01:13:46 +0000 (01:13 +0000)
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>

misc/cgo/test/issue26743.go [new file with mode: 0644]
misc/cgo/test/issue26743/a.go [new file with mode: 0644]
misc/cgo/test/issue26743/b.go [new file with mode: 0644]
src/cmd/cgo/main.go

diff --git a/misc/cgo/test/issue26743.go b/misc/cgo/test/issue26743.go
new file mode 100644 (file)
index 0000000..35c8473
--- /dev/null
@@ -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 (file)
index 0000000..a3df179
--- /dev/null
@@ -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 (file)
index 0000000..c5f1ae4
--- /dev/null
@@ -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
index 2b3e6a0a01d9b351ab067de4bda79a8e8f5fa581..c3c53b35c013b256afecd4d88a1a5a1a301dee9f 100644 (file)
@@ -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))
                        }