aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-21 19:27:12 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-25 23:54:36 +0000
commitdeaf29a8a8ab76613bf0d5d97c4e31bfbdc4c4e9 (patch)
treeeceb1c0bc805e7e82536d7ba77ad5b49dfd48031 /test
parentad2ca26a521a5a642f51c3ef8e3004c9ce7af5aa (diff)
downloadgo-deaf29a8a8ab76613bf0d5d97c4e31bfbdc4c4e9.tar.gz
go-deaf29a8a8ab76613bf0d5d97c4e31bfbdc4c4e9.zip
cmd/compile: fix order-of-assignment issue w/ defers
CL 261677 fixed a logic issue in walk's alias detection, where it was checking the RHS expression instead of the LHS expression when trying to determine the kind of assignment. However, correcting this exposed a latent issue with assigning to result parameters in functions with defers, where an assignment could become visible earlier than intended if a later expression could panic. Fixes #43835. Change-Id: I061ced125e3896e26d65f45b28c99db2c8a74a8c Reviewed-on: https://go-review.googlesource.com/c/go/+/285633 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> Trust: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue43835.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/fixedbugs/issue43835.go b/test/fixedbugs/issue43835.go
new file mode 100644
index 0000000000..449eb72ee1
--- /dev/null
+++ b/test/fixedbugs/issue43835.go
@@ -0,0 +1,33 @@
+// run
+
+// Copyright 2021 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 main
+
+func main() {
+ if f() {
+ panic("FAIL")
+ }
+ if bad, _ := g(); bad {
+ panic("FAIL")
+ }
+}
+
+func f() (bad bool) {
+ defer func() {
+ recover()
+ }()
+ var p *int
+ bad, _ = true, *p
+ return
+}
+
+func g() (bool, int) {
+ defer func() {
+ recover()
+ }()
+ var p *int
+ return true, *p
+}