]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: initialize posBaseMap correctly
authorRobert Griesemer <gri@golang.org>
Fri, 17 May 2024 03:12:26 +0000 (20:12 -0700)
committerGopher Robot <gobot@golang.org>
Mon, 20 May 2024 20:44:21 +0000 (20:44 +0000)
commitb8a410c434b297e95270dea17982c02de0f6609b
treeb14b8939399b07ef3c3a0f2a05c4d0d11a754747
parent1028d973d2854fa3e22d96a0370698e61363a222
cmd/compile: initialize posBaseMap correctly

The posBaseMap is used to identify a file's syntax tree node
given a source position. The position is mapped to the file
base which is then used to look up the file node in posBaseMap.

When posBaseMap is initialized, the file position base
is not the file base if there's a line directive before
the package clause. This can happen in cgo-generated files,
for instance due to an import "C" declaration.

If the wrong file position base is used during initialization,
looking up a file given a position will not find the file.

If a version error occurs and the corresponding file is
not found, the old code panicked with a null pointer exception.

Make sure to consistently initialize the posBaseMap by factoring
out the code computing the file base from a given position.

While at it, check for a nil file pointer. This should not happen
anymore, but don't crash if it happens (at the cost of a slightly
less informative error message).

Fixes #67141.

Change-Id: I4a6af88699c32ad01fffce124b06bb7f9e06f43d
Reviewed-on: https://go-review.googlesource.com/c/go/+/586238
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Robert Griesemer <gri@google.com>
src/cmd/compile/internal/noder/irgen.go
test/fixedbugs/issue67141.go [new file with mode: 0644]