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

cmd/cgo: don't report inconsistency error for incomplete typedef

In CLs 122575 and 123177 the cgo tool started explicitly looking up
typedefs. When there are two Go files using import "C", and the first
one has an incomplete typedef and the second one has a complete
version of the same typedef, then we will now record a version of the
first typedef which will not match the recorded version of the second
typedef, producing an "inconsistent definitions" error. Fix this by
silently merging incomplete typedefs with complete ones.

Fixes #26430

Change-Id: I9e629228783b866dd29b5c3a31acd48f6e410a2d
Reviewed-on: https://go-review.googlesource.com/124575
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent 0d937582
// 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 26430: incomplete typedef leads to inconsistent typedefs error.
// No runtime test; just make sure it compiles.
package cgotest
import _ "./issue26430"
// 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 a
// typedef struct S ST;
// static ST* F() { return 0; }
import "C"
func F1() {
C.F()
}
// 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 a
// typedef struct S ST;
// struct S { int f; };
import "C"
func F2(p *C.ST) {
p.f = 1
}
......@@ -399,6 +399,10 @@ func (p *Package) Record(f *File) {
for k, v := range f.Name {
if p.Name[k] == nil {
p.Name[k] = v
} else if p.incompleteTypedef(p.Name[k].Type) {
p.Name[k] = v
} else if p.incompleteTypedef(v.Type) {
// Nothing to do.
} else if !reflect.DeepEqual(p.Name[k], v) {
error_(token.NoPos, "inconsistent definitions for C.%s", fixGo(k))
}
......@@ -411,3 +415,9 @@ func (p *Package) Record(f *File) {
}
p.Decl = append(p.Decl, f.AST.Decls...)
}
// incompleteTypedef reports whether t appears to be an incomplete
// typedef definition.
func (p *Package) incompleteTypedef(t *Type) bool {
return t == nil || (t.Size == 0 && t.Align == -1)
}
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