]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix inlining of constant if statements
authorMatthew Dempsky <mdempsky@google.com>
Tue, 27 Feb 2018 19:14:11 +0000 (11:14 -0800)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 27 Feb 2018 19:27:32 +0000 (19:27 +0000)
We accidentally overlooked needing to still visit Ninit for OIF
statements with constant conditions in golang.org/cl/96778.

Fixes #24120.

Change-Id: I5b341913065ff90e1163fb872b9e8d47e2a789d2
Reviewed-on: https://go-review.googlesource.com/97475
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

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

index 60df4d06fdf072490130073e1aa2202e32a87433..85bbb4b4f338e71451832614cb251bce0dbab94c 100644 (file)
@@ -363,7 +363,8 @@ func (v *hairyVisitor) visit(n *Node) bool {
        case OIF:
                if Isconst(n.Left, CTBOOL) {
                        // This if and the condition cost nothing.
-                       return v.visitList(n.Nbody) || v.visitList(n.Rlist)
+                       return v.visitList(n.Ninit) || v.visitList(n.Nbody) ||
+                               v.visitList(n.Rlist)
                }
        }
 
diff --git a/test/fixedbugs/issue24120.go b/test/fixedbugs/issue24120.go
new file mode 100644 (file)
index 0000000..6c7d871
--- /dev/null
@@ -0,0 +1,14 @@
+// compile
+
+// Copyright 2018 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.
+
+package p
+
+var F func(int)
+
+func G() {
+       if F(func() int { return 1 }()); false {
+       }
+}