]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: handle DOT STRUCTLIT for zero-valued struct in SSA
authorCherry Zhang <cherryyz@google.com>
Wed, 8 Feb 2017 20:31:24 +0000 (15:31 -0500)
committerCherry Zhang <cherryyz@google.com>
Wed, 8 Feb 2017 21:01:51 +0000 (21:01 +0000)
CL 35261 makes SSA handle zero-valued STRUCTLIT, but DOT operation
was not handled.

Fixes #18994.

Change-Id: Ic7976036acca1523b0b14afac4d170797e8aee20
Reviewed-on: https://go-review.googlesource.com/36565
Run-TryBot: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/compile/internal/gc/ssa.go
test/fixedbugs/issue18994.go [new file with mode: 0644]

index 7d362fb3112a2dea646fbe0f937be8eb647b2b67..1f0f1b0d91caf67e86617d3fee91eb4cb19b0496 100644 (file)
@@ -1956,6 +1956,15 @@ func (s *state) expr(n *Node) *ssa.Value {
                        v := s.expr(n.Left)
                        return s.newValue1I(ssa.OpStructSelect, n.Type, int64(fieldIdx(n)), v)
                }
+               if n.Left.Op == OSTRUCTLIT {
+                       // All literals with nonzero fields have already been
+                       // rewritten during walk. Any that remain are just T{}
+                       // or equivalents. Use the zero value.
+                       if !iszero(n.Left) {
+                               Fatalf("literal with nonzero value in SSA: %v", n.Left)
+                       }
+                       return s.zeroVal(n.Type)
+               }
                p, _ := s.addr(n, false)
                return s.newValue2(ssa.OpLoad, n.Type, p, s.mem())
 
diff --git a/test/fixedbugs/issue18994.go b/test/fixedbugs/issue18994.go
new file mode 100644 (file)
index 0000000..aa30713
--- /dev/null
@@ -0,0 +1,22 @@
+// run
+
+// Copyright 2017 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 18994: SSA didn't handle DOT STRUCTLIT for zero-valued
+// STRUCTLIT.
+
+package main
+
+// large struct - not SSA-able
+type T struct {
+       a, b, c, d, e, f, g, h int
+}
+
+func main() {
+       x := T{}.a
+       if x != 0 {
+               panic("FAIL")
+       }
+}