From d7cd61ceaac488e3130ccf9dd12eeaa13df8e814 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 27 Feb 2018 11:14:11 -0800 Subject: [PATCH] cmd/compile: fix inlining of constant if statements 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 Reviewed-by: Josh Bleecher Snyder TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/inl.go | 3 ++- test/fixedbugs/issue24120.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue24120.go diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index 60df4d06fd..85bbb4b4f3 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -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 index 0000000000..6c7d871b76 --- /dev/null +++ b/test/fixedbugs/issue24120.go @@ -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 { + } +}