]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/cgo: don't let #cgo directives mess up line numbering
authorIan Lance Taylor <iant@golang.org>
Wed, 4 Sep 2013 04:15:15 +0000 (21:15 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 4 Sep 2013 04:15:15 +0000 (21:15 -0700)
Fixes #5272.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/13498046

misc/cgo/errors/err1.go [new file with mode: 0644]
misc/cgo/errors/test.bash [new file with mode: 0755]
src/cmd/cgo/gcc.go
src/run.bash

diff --git a/misc/cgo/errors/err1.go b/misc/cgo/errors/err1.go
new file mode 100644 (file)
index 0000000..78094c6
--- /dev/null
@@ -0,0 +1,14 @@
+package main
+
+/*
+#cgo LDFLAGS: -c
+
+void test() {
+       xxx;            // This is line 7.
+}
+*/
+import "C"
+
+func main() {
+       C.test()
+}
diff --git a/misc/cgo/errors/test.bash b/misc/cgo/errors/test.bash
new file mode 100755 (executable)
index 0000000..e9fa6d0
--- /dev/null
@@ -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
index f4700946634f511d98a0b5c07e63114d09b3bead..d835accac1b57b9725c34c143186f8eb66ba6463 100644 (file)
@@ -76,6 +76,8 @@ func (f *File) DiscardCgoDirectives() {
                l := strings.TrimSpace(line)
                if len(l) < 5 || l[:4] != "#cgo" || !unicode.IsSpace(rune(l[4])) {
                        linesOut = append(linesOut, line)
+               } else {
+                       linesOut = append(linesOut, "")
                }
        }
        f.Preamble = strings.Join(linesOut, "\n")
index 52e09b49793ad1b835df0551fa5e607539c1b173..9af3f95b074aa3eb0afa963d31a44c6243faef9e 100755 (executable)
@@ -145,6 +145,12 @@ esac
 go run main.go || exit 1
 ) || exit $?
 
+[ "$CGO_ENABLED" != 1 ] ||
+[ "$GOHOSTOS" == windows ] ||
+(xcd ../misc/cgo/errors
+./test.bash || exit 1
+) || exit $?
+
 (xcd ../doc/progs
 time ./run || exit 1
 ) || exit $?