mirror of
https://github.com/golang/go
synced 2024-11-20 03:04:40 -07:00
cgo: print error instead of panic on undeclared enums/structs
Types are left as nil if no DWARF information is found and checking in the rewriting pass so that appropriate errors with line numbers can be printed. Fixes #2408. R=rsc CC=golang-dev, remy https://golang.org/cl/5336041
This commit is contained in:
parent
17105870ff
commit
23ffbe611d
@ -577,6 +577,9 @@ func (p *Package) loadDWARF(f *File, names []*Name) {
|
|||||||
var conv typeConv
|
var conv typeConv
|
||||||
conv.Init(p.PtrSize)
|
conv.Init(p.PtrSize)
|
||||||
for i, n := range names {
|
for i, n := range names {
|
||||||
|
if types[i] == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
f, fok := types[i].(*dwarf.FuncType)
|
f, fok := types[i].(*dwarf.FuncType)
|
||||||
if n.Kind != "type" && fok {
|
if n.Kind != "type" && fok {
|
||||||
n.Kind = "func"
|
n.Kind = "func"
|
||||||
@ -664,6 +667,10 @@ func (p *Package) rewriteRef(f *File) {
|
|||||||
case "type":
|
case "type":
|
||||||
if r.Name.Kind != "type" {
|
if r.Name.Kind != "type" {
|
||||||
error_(r.Pos(), "expression C.%s used as type", r.Name.Go)
|
error_(r.Pos(), "expression C.%s used as type", r.Name.Go)
|
||||||
|
} else if r.Name.Type == nil {
|
||||||
|
// Use of C.enum_x, C.struct_x or C.union_x without C definition.
|
||||||
|
// GCC won't raise an error when using pointers to such unknown types.
|
||||||
|
error_(r.Pos(), "type C.%s: undefined C type '%s'", r.Name.Go, r.Name.C)
|
||||||
} else {
|
} else {
|
||||||
expr = r.Name.Type.Go
|
expr = r.Name.Type.Go
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user