From d3886906b18d292643117b55c987ec9b35b226b3 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 18 Sep 2015 22:12:38 -0700 Subject: [PATCH] [dev.ssa] cmd/compile: implement OSTRUCTLIT and OARRAYLIT 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/ssa.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 186c1a2996..fb7e0c54ac 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -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!