Commit c29370c9 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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/127356Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent a2ef8b9c
// 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"
// 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)
// 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
...@@ -403,6 +403,10 @@ func (p *Package) Record(f *File) { ...@@ -403,6 +403,10 @@ func (p *Package) Record(f *File) {
p.Name[k] = v p.Name[k] = v
} else if p.incompleteTypedef(v.Type) { } else if p.incompleteTypedef(v.Type) {
// Nothing to do. // 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) { } else if !reflect.DeepEqual(p.Name[k], v) {
error_(token.NoPos, "inconsistent definitions for C.%s", fixGo(k)) error_(token.NoPos, "inconsistent definitions for C.%s", fixGo(k))
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment