aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2016-12-28 17:29:25 -0800
committerRobert Griesemer <gri@golang.org>2017-01-09 19:39:56 +0000
commitf412bd31ce1859ea1dd0d46ec1b130c44b480115 (patch)
treecd28a19b27abb6f0b5dedf66d52c80e2ee88d547
parenta8871194f296383d313972da083e1b5f7513dfeb (diff)
downloadgo-f412bd31ce1859ea1dd0d46ec1b130c44b480115.tar.gz
go-f412bd31ce1859ea1dd0d46ec1b130c44b480115.zip
cmd/compile: file line number for //go:xxx directives
Minimally invasive; fixes a regression from 1.7. Fixes #18459. Change-Id: I93b3b5c05706eaff8ae97a237f770838c1f8778c Reviewed-on: https://go-review.googlesource.com/34721 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/cmd/compile/internal/gc/noder.go2
-rw-r--r--src/go/types/stdlib_test.go1
-rw-r--r--test/fixedbugs/issue18459.go13
3 files changed, 16 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/gc/noder.go b/src/cmd/compile/internal/gc/noder.go
index a501cb67b6..ca99adea27 100644
--- a/src/cmd/compile/internal/gc/noder.go
+++ b/src/cmd/compile/internal/gc/noder.go
@@ -1055,6 +1055,7 @@ func (p *noder) pragma(pos, line int, text string) syntax.Pragma {
lookup(f[1]).Linkname = f[2]
case strings.HasPrefix(text, "go:cgo_"):
+ lineno = p.baseline + int32(line) - 1 // pragcgo may call yyerror
pragcgobuf += pragcgo(text)
fallthrough // because of //go:cgo_unsafe_args
default:
@@ -1062,6 +1063,7 @@ func (p *noder) pragma(pos, line int, text string) syntax.Pragma {
if i := strings.Index(text, " "); i >= 0 {
verb = verb[:i]
}
+ lineno = p.baseline + int32(line) - 1 // pragmaValue may call yyerror
return syntax.Pragma(pragmaValue(verb))
}
diff --git a/src/go/types/stdlib_test.go b/src/go/types/stdlib_test.go
index 1c6d7b5299..06d2c93dda 100644
--- a/src/go/types/stdlib_test.go
+++ b/src/go/types/stdlib_test.go
@@ -157,6 +157,7 @@ func TestStdFixed(t *testing.T) {
"issue11362.go", // canonical import path check
"issue15002.go", // uses Mmap; testTestDir should consult build tags
"issue16369.go", // go/types handles this correctly - not an issue
+ "issue18459.go", // go/types doesn't check validity of //go:xxx directives
)
}
diff --git a/test/fixedbugs/issue18459.go b/test/fixedbugs/issue18459.go
new file mode 100644
index 0000000000..ac07661d63
--- /dev/null
+++ b/test/fixedbugs/issue18459.go
@@ -0,0 +1,13 @@
+// errorcheck
+
+// Copyright 2016 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.
+
+// Verify that we have a line number for this error.
+
+package main
+
+//go:nowritebarrier // ERROR "go:nowritebarrier only allowed in runtime"
+func main() {
+}