]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: implement OSTRUCTLIT and OARRAYLIT
authorKeith Randall <khr@golang.org>
Sat, 19 Sep 2015 05:12:38 +0000 (22:12 -0700)
committerKeith Randall <khr@golang.org>
Sat, 19 Sep 2015 18:21:02 +0000 (18:21 +0000)
The frontend rewrites most literals, so we see only zero
ones during SSA construction.  We can implement those
using the existing zeroing behavior.

Change-Id: I390ad1be0a4b6729baf0c8936c7610aae2aef049
Reviewed-on: https://go-review.googlesource.com/14754
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/ssa.go

index 186c1a29963fb1f5c4219d8d466dbff89d3645bd..fb7e0c54ac83bade3b2e21637657979c0f67163e 100644 (file)
@@ -574,7 +574,16 @@ func (s *state) stmt(n *Node) {
                }
                var r *ssa.Value
                if n.Right != nil {
-                       r = s.expr(n.Right)
+                       if n.Right.Op == OSTRUCTLIT || n.Right.Op == OARRAYLIT {
+                               // All literals with nonzero fields have already been
+                               // rewritten during walk.  Any that remain are just T{}
+                               // or equivalents.  Leave r = nil to get zeroing behavior.
+                               if !iszero(n.Right) {
+                                       Fatalf("literal with nonzero value in SSA: %v", n.Right)
+                               }
+                       } else {
+                               r = s.expr(n.Right)
+                       }
                }
                if n.Right != nil && n.Right.Op == OAPPEND {
                        // Yuck!  The frontend gets rid of the write barrier, but we need it!