Commit 08b26e41 authored by Russ Cox's avatar Russ Cox

cmd/cgo: don't say "gcc produced no output" if we ran clang

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13420048
parent 71ed6eb2
...@@ -311,7 +311,7 @@ func (p *Package) guessKinds(f *File) []*Name { ...@@ -311,7 +311,7 @@ func (p *Package) guessKinds(f *File) []*Name {
b.WriteString("}\n") b.WriteString("}\n")
stderr := p.gccErrors(b.Bytes()) stderr := p.gccErrors(b.Bytes())
if stderr == "" { if stderr == "" {
fatalf("gcc produced no output\non input:\n%s", b.Bytes()) fatalf("%s produced no output\non input:\n%s", p.gccBaseCmd()[0], b.Bytes())
} }
names := make([]*Name, len(toSniff)) names := make([]*Name, len(toSniff))
...@@ -383,7 +383,7 @@ func (p *Package) guessKinds(f *File) []*Name { ...@@ -383,7 +383,7 @@ func (p *Package) guessKinds(f *File) []*Name {
if n.Kind != "" { if n.Kind != "" {
continue continue
} }
error_(token.NoPos, "could not determine kind of name for C.%s", n.Go) error_(token.NoPos, "could not determine kind of name for C.%s", fixGo(n.Go))
} }
if nerrors > 0 { if nerrors > 0 {
fatalf("unresolved names") fatalf("unresolved names")
...@@ -593,7 +593,7 @@ func (p *Package) rewriteRef(f *File) { ...@@ -593,7 +593,7 @@ func (p *Package) rewriteRef(f *File) {
// functions are only used in calls. // functions are only used in calls.
for _, r := range f.Ref { for _, r := range f.Ref {
if r.Name.Kind == "const" && r.Name.Const == "" { if r.Name.Kind == "const" && r.Name.Const == "" {
error_(r.Pos(), "unable to find value of constant C.%s", r.Name.Go) error_(r.Pos(), "unable to find value of constant C.%s", fixGo(r.Name.Go))
} }
var expr ast.Expr = ast.NewIdent(r.Name.Mangle) // default var expr ast.Expr = ast.NewIdent(r.Name.Mangle) // default
switch r.Context { switch r.Context {
...@@ -604,11 +604,15 @@ func (p *Package) rewriteRef(f *File) { ...@@ -604,11 +604,15 @@ func (p *Package) rewriteRef(f *File) {
expr = r.Name.Type.Go expr = r.Name.Type.Go
break break
} }
error_(r.Pos(), "call of non-function C.%s", r.Name.Go) error_(r.Pos(), "call of non-function C.%s", fixGo(r.Name.Go))
break break
} }
functions[r.Name.Go] = true functions[r.Name.Go] = true
if r.Context == "call2" { if r.Context == "call2" {
if r.Name.Go == "_CMalloc" {
error_(r.Pos(), "no two-result form for C.malloc")
break
}
// Invent new Name for the two-result function. // Invent new Name for the two-result function.
n := f.Name["2"+r.Name.Go] n := f.Name["2"+r.Name.Go]
if n == nil { if n == nil {
...@@ -649,17 +653,17 @@ func (p *Package) rewriteRef(f *File) { ...@@ -649,17 +653,17 @@ 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", fixGo(r.Name.Go))
} else if r.Name.Type == nil { } else if r.Name.Type == nil {
// Use of C.enum_x, C.struct_x or C.union_x without C definition. // 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. // 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) error_(r.Pos(), "type C.%s: undefined C type '%s'", fixGo(r.Name.Go), r.Name.C)
} else { } else {
expr = r.Name.Type.Go expr = r.Name.Type.Go
} }
default: default:
if r.Name.Kind == "func" { if r.Name.Kind == "func" {
error_(r.Pos(), "must call C.%s", r.Name.Go) error_(r.Pos(), "must call C.%s", fixGo(r.Name.Go))
} }
} }
if *godefs || *cdefs { if *godefs || *cdefs {
......
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