]> Cypherpunks repositories - gostls13.git/commit
cmd/cgo: add #line directives to avoid printing bogus references to Go source files
authorRuss Cox <rsc@golang.org>
Wed, 2 Nov 2016 23:41:01 +0000 (19:41 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 3 Nov 2016 16:35:25 +0000 (16:35 +0000)
commitb2290229c23fed8e4a63241568e436b1daa1196f
tree70154d0138db58999240142ae134034ec5c85f65
parenta4a4d43028ba20ecec50ef761012d17800553cde
cmd/cgo: add #line directives to avoid printing bogus references to Go source files

A bit contrived to come up with an example, but it happened in #15836, somehow.

$ cat /tmp/x.go
package main

/*
#include <stddef.h>

int foo(void);

int foo(void) {
return 2;
}

#define int asdf
*/
import "C"

func main() {
println(C.foo())
}

$ go run /tmp/x.go
# command-line-arguments
cgo-builtin-prolog:9:31: error: unknown type name 'asdf'   <<<<<
_GoString_ GoStringN(char *p, int l);
                              ^
/tmp/x.go:12:13: note: expanded from macro 'int'
#define int asdf
            ^
cgo-builtin-prolog:10:28: error: unknown type name 'asdf'  <<<<<
_GoBytes_ GoBytes(void *p, int n);
                           ^
/tmp/x.go:12:13: note: expanded from macro 'int'
#define int asdf
            ^
2 errors generated.

The two marked lines used to refer incorrectly to /tmp/x.go.

Fixes #15836.

Change-Id: I08ef60a53cfd148112fceb651eaf7b75d94a7a8d
Reviewed-on: https://go-review.googlesource.com/32613
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/cgo/ast.go
src/cmd/cgo/gcc.go
src/cmd/cgo/out.go