Skip to content

Commit

Permalink
cmd/compile: fix position of fake receivers; be more careful in logopt
Browse files Browse the repository at this point in the history
The src.NoXPos in fake receivers was leaking, through a series of
mishaps, all the way to logopt.  If done just so, this can lead to
a compiler crash.  This makes logopt crash-proof and eliminates the
root cause as well.

I'm reluctant to write a test for this because it's kinda slow
and involved; my working test is "compile something that mentions
the flag package with -json=0,$TMPDIR flag, then be sure that
$TMPDIR/flag/__unnamed__.json was not created".

Change-Id: I384b717c0e7522953d22d61f7e06319e11192d7d
Reviewed-on: https://go-review.googlesource.com/c/go/+/443156
Run-TryBot: David Chase <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Michael Pratt <[email protected]>
  • Loading branch information
dr2chase authored and romaindoumenc committed Nov 3, 2022
1 parent a4b78ca commit e292db5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/logopt/log_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ func uriIfy(f string) DocumentURI {
// Return filename, replacing a first occurrence of $GOROOT with the
// actual value of the GOROOT (because LSP does not speak "$GOROOT").
func uprootedPath(filename string) string {
if filename == "" {
return "__unnamed__"
}
if buildcfg.GOROOT == "" || !strings.HasPrefix(filename, "$GOROOT/") {
return filename
}
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/types/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ func FakeRecvType() *Type {
}

func FakeRecv() *Field {
return NewField(src.NoXPos, nil, FakeRecvType())
return NewField(base.AutogeneratedPos, nil, FakeRecvType())
}

var (
Expand Down

0 comments on commit e292db5

Please sign in to comment.