aboutsummaryrefslogtreecommitdiff
path: root/test/closure3.go
diff options
context:
space:
mode:
authorHugues Bruant <hugues.bruant@gmail.com>2017-11-02 19:54:46 -0700
committerKeith Randall <khr@golang.org>2017-11-03 20:09:26 +0000
commit483e298daad38f39515ba20c0fcedc20b5475ae8 (patch)
treee825b91aa124c364def4e6be57224f3b8a29b590 /test/closure3.go
parentd593f85ebdcdb36938e5c3e56fedc7852d713d18 (diff)
downloadgo-483e298daad38f39515ba20c0fcedc20b5475ae8.tar.gz
go-483e298daad38f39515ba20c0fcedc20b5475ae8.zip
cmd/compile: fix reassignment check
CL 65071 enabled inlining for local closures with no captures. To determine safety of inlining a call sites, we check whether the variable holding the closure has any assignments after its original definition. Unfortunately, that check did not catch OAS2MAPR and OAS2DOTTYPE, leading to incorrect inlining when a variable holding a closure was subsequently reassigned through a type conversion or a 2-valued map access. There was another more subtle issue wherein reassignment check would always return a false positive for closure calls inside other closures. This was caused by the Name.Curfn field of local variables pointing to the OCLOSURE node instead of the corresponding ODCLFUNC, which resulted in reassigned walking an empty Nbody and thus never seeing any reassignments. This CL fixes these oversights and adds many more tests for closure inlining which ensure not only that inlining triggers but also the correctness of the resulting code. Updates #15561 Change-Id: I74bdae849c4ecfa328546d6d62b512e8d54d04ce Reviewed-on: https://go-review.googlesource.com/75770 Reviewed-by: Hugues Bruant <hugues.bruant@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/closure3.go')
-rw-r--r--test/closure3.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/closure3.go b/test/closure3.go
new file mode 100644
index 0000000000..263d8fcb47
--- /dev/null
+++ b/test/closure3.go
@@ -0,0 +1,10 @@
+// errorcheckandrundir -0 -m
+
+// 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.
+
+// Check correctness of various closure corner cases that
+// that are expected to be inlined
+
+package ignored