diff --git a/src/cmd/gc/closure.c b/src/cmd/gc/closure.c index b067228052..5d25ffe4ad 100644 --- a/src/cmd/gc/closure.c +++ b/src/cmd/gc/closure.c @@ -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 index 0000000000..85319d70a7 --- /dev/null +++ b/test/fixedbugs/issue9738.go @@ -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() +}