]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.regabi] cmd/compile: remove SetOp(OEMPTY) calls
authorRuss Cox <rsc@golang.org>
Sat, 28 Nov 2020 05:54:58 +0000 (00:54 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 30 Nov 2020 18:33:52 +0000 (18:33 +0000)
In preparation for OEMPTY being its own Node implementation,
remove SetOp(OEMPTY) calls that assume other implementations
can be turned into OEMPTY.

Passes buildall w/ toolstash -cmp.

Change-Id: Icac16d12548f35f52a5efa9d09dacf8260f42075
Reviewed-on: https://go-review.googlesource.com/c/go/+/274090
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/sinit.go
src/cmd/compile/internal/gc/typecheck.go
src/cmd/compile/internal/gc/walk.go

index e30663cfbb8fa94a376e1506706dc71cf310aa43..fca81763c0f0a2a91c67dc88ed1ba66c653b2d9a 100644 (file)
@@ -959,6 +959,9 @@ func anylit(n ir.Node, var_ ir.Node, init *ir.Nodes) {
        }
 }
 
+// oaslit handles special composite literal assignments.
+// It returns true if n's effects have been added to init,
+// in which case n should be dropped from the program by the caller.
 func oaslit(n ir.Node, init *ir.Nodes) bool {
        if n.Left() == nil || n.Right() == nil {
                // not a special composite literal assignment
@@ -990,8 +993,6 @@ func oaslit(n ir.Node, init *ir.Nodes) bool {
                anylit(n.Right(), n.Left(), init)
        }
 
-       n.SetOp(ir.OEMPTY)
-       n.SetRight(nil)
        return true
 }
 
index 7037eddff0c6efd78444256b787d45c02f2abc99..0c4a3ad833a51e92dd25e4aee0ed20bb796d603e 100644 (file)
@@ -1985,8 +1985,7 @@ func typecheck1(n ir.Node, top int) (res ir.Node) {
                        // Empty identifier is valid but useless.
                        // Eliminate now to simplify life later.
                        // See issues 7538, 11589, 11593.
-                       n.SetOp(ir.OEMPTY)
-                       n.SetLeft(nil)
+                       n = ir.NodAt(n.Pos(), ir.OEMPTY, nil, nil)
                }
 
        case ir.ODEFER:
index db8791ee05780287ecdcff719043655751674fb7..87fe36b08a0104a0dc5015e2ce3c1a46dc2e5753 100644 (file)
@@ -152,10 +152,12 @@ func walkstmt(n ir.Node) ir.Node {
                init := n.Init()
                n.PtrInit().Set(nil)
                n = walkexpr(n, &init)
-               n = addinit(n, init.Slice())
-               if wascopy && n.Op() == ir.OCONVNOP {
-                       n.SetOp(ir.OEMPTY) // don't leave plain values as statements.
+               if wascopy && n.Op() == ir.ONAME {
+                       // copy rewrote to a statement list and a temp for the length.
+                       // Throw away the temp to avoid plain values as statements.
+                       n = ir.NodAt(n.Pos(), ir.OEMPTY, nil, nil)
                }
+               n = addinit(n, init.Slice())
 
        // special case for a receive where we throw away
        // the value received.
@@ -609,6 +611,7 @@ opswitch:
                }
 
                if oaslit(n, init) {
+                       n = ir.NodAt(n.Pos(), ir.OEMPTY, nil, nil)
                        break
                }