Skip to content

Commit f412bd3

Browse files
committed
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 <[email protected]> Reviewed-by: Russ Cox <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent a887119 commit f412bd3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/cmd/compile/internal/gc/noder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,13 +1055,15 @@ func (p *noder) pragma(pos, line int, text string) syntax.Pragma {
10551055
lookup(f[1]).Linkname = f[2]
10561056

10571057
case strings.HasPrefix(text, "go:cgo_"):
1058+
lineno = p.baseline + int32(line) - 1 // pragcgo may call yyerror
10581059
pragcgobuf += pragcgo(text)
10591060
fallthrough // because of //go:cgo_unsafe_args
10601061
default:
10611062
verb := text
10621063
if i := strings.Index(text, " "); i >= 0 {
10631064
verb = verb[:i]
10641065
}
1066+
lineno = p.baseline + int32(line) - 1 // pragmaValue may call yyerror
10651067
return syntax.Pragma(pragmaValue(verb))
10661068
}
10671069

src/go/types/stdlib_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func TestStdFixed(t *testing.T) {
157157
"issue11362.go", // canonical import path check
158158
"issue15002.go", // uses Mmap; testTestDir should consult build tags
159159
"issue16369.go", // go/types handles this correctly - not an issue
160+
"issue18459.go", // go/types doesn't check validity of //go:xxx directives
160161
)
161162
}
162163

test/fixedbugs/issue18459.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// errorcheck
2+
3+
// Copyright 2016 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Verify that we have a line number for this error.
8+
9+
package main
10+
11+
//go:nowritebarrier // ERROR "go:nowritebarrier only allowed in runtime"
12+
func main() {
13+
}

0 commit comments

Comments
 (0)