• Russ Cox's avatar
    cmd/cgo: add #line directives to avoid printing bogus references to Go source files · b2290229
    Russ Cox authored
    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: 's avatarIan Lance Taylor <iant@golang.org>
    b2290229
Name
Last commit
Last update
.github Loading commit data...
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...