diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 7d362fb3112..1f0f1b0d91c 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -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 index 00000000000..aa307139f53 --- /dev/null +++ b/test/fixedbugs/issue18994.go @@ -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") + } +}