]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: always treat the output parameters as having been assigned in capturevars.
authorShenghou Ma <minux@golang.org>
Sat, 31 Jan 2015 07:50:56 +0000 (02:50 -0500)
committerMinux Ma <minux@golang.org>
Mon, 2 Feb 2015 14:14:21 +0000 (14:14 +0000)
Fixes #9738.

Change-Id: Iab75de2d78335d4e31c3dce6a0e1826d8cddf5f3
Reviewed-on: https://go-review.googlesource.com/3690
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
src/cmd/gc/closure.c
test/fixedbugs/issue9738.go [new file with mode: 0644]

index b0672280528c6d58321b5be2d30f0f06e2429e8d..5d25ffe4ad133e8f8d7b22d873f7cfaafe232fda 100644 (file)
@@ -209,7 +209,8 @@ capturevars(Node *xfunc)
                dowidth(v->type);
                outer = v->outerexpr;
                v->outerexpr = N;
-               if(!v->closure->addrtaken && !v->closure->assigned && v->type->width <= 128)
+               // out parameters will be assigned to implicitly upon return.
+               if(outer->class != PPARAMOUT && !v->closure->addrtaken && !v->closure->assigned && v->type->width <= 128)
                        v->byval = 1;
                else {
                        outer = nod(OADDR, outer, N);
diff --git a/test/fixedbugs/issue9738.go b/test/fixedbugs/issue9738.go
new file mode 100644 (file)
index 0000000..85319d7
--- /dev/null
@@ -0,0 +1,20 @@
+// run
+
+// Copyright 2015 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 F() (x int) {
+       defer func() {
+               if x != 42 {
+                       println("BUG: x =", x)
+               }
+       }()
+       return 42
+}
+
+func main() {
+       F()
+}