]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: use ir.Copy instead of direct use of RawCopy
authorRuss Cox <rsc@golang.org>
Tue, 1 Dec 2020 02:18:48 +0000 (21:18 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 1 Dec 2020 12:34:46 +0000 (12:34 +0000)
The ONIL export bug happened because the logic about
maintaining an “implicit” orig pointer in the comments
around ir.Orig only applies to Copy and SepCopy, not to
direct use of RawCopy. I'd forgotten those could exist.

The sole direct use of RawCopy was for the OLITERAL/ONIL case.
The ONIL is now provably indistinguishable from Copy, since
NilExpr does not have an explicit Orig field, so for NilExpr
RawCopy and Copy are the same.
The OLITERAL is not, but we can reconstruct the effect
with Copy+SetOrig to be explicit that we need the orig link.

The next CL will unexport RawCopy.

Also fix a typo in MapType doc comment.

Passes buildall w/ toolstash -cmp.

Change-Id: I876a85ff188e6d1cd4c0dfa385be32482e0de0d4
Reviewed-on: https://go-review.googlesource.com/c/go/+/274292
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/gc/const.go
src/cmd/compile/internal/ir/type.go

index 3c161d8e127d909abb23601e7efc55b6e4b5b790..4dee373bfa55c1cf715b04341cf8286643d8d71b 100644 (file)
@@ -118,7 +118,12 @@ func convlit1(n ir.Node, t *types.Type, explicit bool, context func() string) ir
        if n.Op() == ir.OLITERAL || n.Op() == ir.ONIL {
                // Can't always set n.Type directly on OLITERAL nodes.
                // See discussion on CL 20813.
-               n = n.RawCopy()
+               old := n
+               n = ir.Copy(old)
+               if old.Op() == ir.OLITERAL {
+                       // Keep untyped constants in their original untyped syntax for error messages.
+                       n.(ir.OrigNode).SetOrig(old)
+               }
        }
 
        // Nil is technically not a constant, so handle it specially.
index 39411ed43197658ead487a91029b32ce5c008da3..519a7291b043237973b16e28be2aecf6280a325c 100644 (file)
@@ -92,7 +92,7 @@ func (n *ChanType) DeepCopy(pos src.XPos) Node {
        return NewChanType(n.posOr(pos), DeepCopy(pos, n.Elem), n.Dir)
 }
 
-// A MapType represents a map[Key]Value type syntax.u
+// A MapType represents a map[Key]Value type syntax.
 type MapType struct {
        miniType
        Key  Node