aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/reader.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-09-08 15:59:11 -0700
committerMatthew Dempsky <mdempsky@google.com>2021-09-09 00:10:46 +0000
commite30a09013b24853cbe6d3d3a919e639df0bdf41c (patch)
tree7ff96ac9edf4c5b7353f93ac67845e0c3cc857b3 /src/cmd/compile/internal/noder/reader.go
parenta1f6208e56436281ce5e26ad745f8fc3f7a9b280 (diff)
downloadgo-e30a09013b24853cbe6d3d3a919e639df0bdf41c.tar.xz
cmd/compile: extrapolate $GOROOT in unified IR
This ensures that diagnostics for files within $GOROOT continue to be reported using their full filepath, rather than the abbreviated filepath. Notably, this is necessary for test/run.go, which has tests that expect to see the full filepath. Updates #48247. Change-Id: I440e2c6dd6109ca059d81cee49e476bba805d703 Reviewed-on: https://go-review.googlesource.com/c/go/+/348670 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/noder/reader.go')
-rw-r--r--src/cmd/compile/internal/noder/reader.go24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/cmd/compile/internal/noder/reader.go b/src/cmd/compile/internal/noder/reader.go
index 204d25bce8..b3cb10dadb 100644
--- a/src/cmd/compile/internal/noder/reader.go
+++ b/src/cmd/compile/internal/noder/reader.go
@@ -10,6 +10,7 @@ import (
"bytes"
"fmt"
"go/constant"
+ "internal/buildcfg"
"strings"
"cmd/compile/internal/base"
@@ -194,15 +195,32 @@ func (pr *pkgReader) posBaseIdx(idx int) *src.PosBase {
r := pr.newReader(relocPosBase, idx, syncPosBase)
var b *src.PosBase
- filename := r.string()
+ absFilename := r.string()
+ filename := absFilename
+
+ // For build artifact stability, the export data format only
+ // contains the "absolute" filename as returned by objabi.AbsFile.
+ // However, some tests (e.g., test/run.go's asmcheck tests) expect
+ // to see the full, original filename printed out. Re-expanding
+ // "$GOROOT" to buildcfg.GOROOT is a close-enough approximation to
+ // satisfy this.
+ //
+ // TODO(mdempsky): De-duplicate this logic with similar logic in
+ // cmd/link/internal/ld's expandGoroot. However, this will probably
+ // require being more consistent about when we use native vs UNIX
+ // file paths.
+ const dollarGOROOT = "$GOROOT"
+ if strings.HasPrefix(filename, dollarGOROOT) {
+ filename = buildcfg.GOROOT + filename[len(dollarGOROOT):]
+ }
if r.bool() {
- b = src.NewFileBase(filename, filename)
+ b = src.NewFileBase(filename, absFilename)
} else {
pos := r.pos0()
line := r.uint()
col := r.uint()
- b = src.NewLinePragmaBase(pos, filename, filename, line, col)
+ b = src.NewLinePragmaBase(pos, filename, absFilename, line, col)
}
pr.posBases[idx] = b