1
0
mirror of https://github.com/golang/go synced 2024-11-25 10:07:56 -07:00

cmd/cgo: don't let #cgo directives mess up line numbering

Fixes #5272.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13498046
This commit is contained in:
Ian Lance Taylor 2013-09-03 21:15:15 -07:00
parent 0ba7ffe289
commit f68c23e2bb
4 changed files with 41 additions and 0 deletions

14
misc/cgo/errors/err1.go Normal file
View File

@ -0,0 +1,14 @@
package main
/*
#cgo LDFLAGS: -c
void test() {
xxx; // This is line 7.
}
*/
import "C"
func main() {
C.test()
}

19
misc/cgo/errors/test.bash Executable file
View File

@ -0,0 +1,19 @@
# Copyright 2013 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.
if go tool cgo err1.go >errs 2>&1; then
echo 1>&2 misc/cgo/errors/test.bash: BUG: expected cgo to fail but it succeeded
exit 1
fi
if ! test -s errs; then
echo 1>&2 misc/cgo/errors/test.bash: BUG: expected error output but saw none
exit 1
fi
if ! fgrep err1.go:7 errs >/dev/null 2>&1; then
echo 1>&2 misc/cgo/errors/test.bash: BUG: expected error on line 7 but saw:
cat 1>&2 errs
exit 1
fi
rm -rf errs _obj
exit 0

View File

@ -76,6 +76,8 @@ func (f *File) DiscardCgoDirectives() {
l := strings.TrimSpace(line) l := strings.TrimSpace(line)
if len(l) < 5 || l[:4] != "#cgo" || !unicode.IsSpace(rune(l[4])) { if len(l) < 5 || l[:4] != "#cgo" || !unicode.IsSpace(rune(l[4])) {
linesOut = append(linesOut, line) linesOut = append(linesOut, line)
} else {
linesOut = append(linesOut, "")
} }
} }
f.Preamble = strings.Join(linesOut, "\n") f.Preamble = strings.Join(linesOut, "\n")

View File

@ -145,6 +145,12 @@ esac
go run main.go || exit 1 go run main.go || exit 1
) || exit $? ) || exit $?
[ "$CGO_ENABLED" != 1 ] ||
[ "$GOHOSTOS" == windows ] ||
(xcd ../misc/cgo/errors
./test.bash || exit 1
) || exit $?
(xcd ../doc/progs (xcd ../doc/progs
time ./run || exit 1 time ./run || exit 1
) || exit $? ) || exit $?