]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix position of fake receivers; be more careful in logopt
authorDavid Chase <drchase@google.com>
Fri, 14 Oct 2022 20:24:44 +0000 (16:24 -0400)
committerDavid Chase <drchase@google.com>
Mon, 17 Oct 2022 15:59:12 +0000 (15:59 +0000)
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 <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/cmd/compile/internal/logopt/log_opts.go
src/cmd/compile/internal/types/type.go

index 711b5b9d75c23f4a50c3b2d0e745cd5c4273fbc2..5c7f580f0b2b70356df795a0900ed4b7bc3cd08e 100644 (file)
@@ -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
        }
index f4e6b92bd641c2f8519cfb8249749d123381ee44..8329837a308a002c3247812b2a5acdf83f62a235 100644 (file)
@@ -1680,7 +1680,7 @@ func FakeRecvType() *Type {
 }
 
 func FakeRecv() *Field {
-       return NewField(src.NoXPos, nil, FakeRecvType())
+       return NewField(base.AutogeneratedPos, nil, FakeRecvType())
 }
 
 var (