mirror of
https://github.com/golang/go
synced 2024-11-22 00:24:41 -07:00
gc: bug293
Fixes #846. R=ken2 CC=golang-dev https://golang.org/cl/1862042
This commit is contained in:
parent
cdb446feb5
commit
ece6a8c549
@ -87,12 +87,12 @@ compile(Node *fn)
|
||||
|
||||
if(pret)
|
||||
patch(pret, pc);
|
||||
if(hasdefer)
|
||||
ginscall(deferreturn, 0);
|
||||
if(curfn->exit)
|
||||
genlist(curfn->exit);
|
||||
if(nerrors != 0)
|
||||
goto ret;
|
||||
if(hasdefer)
|
||||
ginscall(deferreturn, 0);
|
||||
pc->as = ARET; // overwrite AEND
|
||||
pc->lineno = lineno;
|
||||
|
||||
|
@ -90,13 +90,13 @@ compile(Node *fn)
|
||||
if(pret)
|
||||
patch(pret, pc);
|
||||
ginit();
|
||||
if(hasdefer)
|
||||
ginscall(deferreturn, 0);
|
||||
if(curfn->exit)
|
||||
genlist(curfn->exit);
|
||||
gclean();
|
||||
if(nerrors != 0)
|
||||
goto ret;
|
||||
if(hasdefer)
|
||||
ginscall(deferreturn, 0);
|
||||
pc->as = ARET; // overwrite AEND
|
||||
pc->lineno = lineno;
|
||||
|
||||
|
@ -92,11 +92,6 @@ compile(Node *fn)
|
||||
if(pret)
|
||||
patch(pret, pc);
|
||||
ginit();
|
||||
if(curfn->exit)
|
||||
genlist(curfn->exit);
|
||||
gclean();
|
||||
if(nerrors != 0)
|
||||
goto ret;
|
||||
if(hasdefer) {
|
||||
// On Native client, insert call to no-op function
|
||||
// to force alignment immediately before call to deferreturn,
|
||||
@ -107,6 +102,11 @@ compile(Node *fn)
|
||||
ginscall(naclnop, 0);
|
||||
ginscall(deferreturn, 0);
|
||||
}
|
||||
if(curfn->exit)
|
||||
genlist(curfn->exit);
|
||||
gclean();
|
||||
if(nerrors != 0)
|
||||
goto ret;
|
||||
pc->as = ARET; // overwrite AEND
|
||||
pc->lineno = lineno;
|
||||
|
||||
|
@ -365,7 +365,7 @@ walkstmt(Node **np)
|
||||
NodeList *init;
|
||||
NodeList *ll, *rl;
|
||||
int cl, lno;
|
||||
Node *n;
|
||||
Node *n, *f;
|
||||
|
||||
n = *np;
|
||||
if(n == N)
|
||||
@ -492,6 +492,14 @@ walkstmt(Node **np)
|
||||
n->list = nil;
|
||||
break;
|
||||
}
|
||||
if(count(n->list) == 1 && count(rl) > 1) {
|
||||
// OAS2FUNC in disguise
|
||||
f = n->list->n;
|
||||
if(f->op != OCALLFUNC && f->op != OCALLMETH && f->op != OCALLINTER)
|
||||
fatal("expected return of call, have %#N", f);
|
||||
n->list = concat(list1(f), ascompatet(n->op, rl, &f->type, 0, &n->ninit));
|
||||
break;
|
||||
}
|
||||
ll = ascompatee(n->op, rl, n->list, &n->ninit);
|
||||
n->list = reorder3(ll);
|
||||
break;
|
||||
|
37
test/fixedbugs/bug293.go
Normal file
37
test/fixedbugs/bug293.go
Normal file
@ -0,0 +1,37 @@
|
||||
// $G $D/$F.go && $L $F.$A && ./$A.out
|
||||
|
||||
// Copyright 2010 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.
|
||||
|
||||
// http://code.google.com/p/go/issues/detail?id=846
|
||||
|
||||
package main
|
||||
|
||||
func x() (a int, b bool) {
|
||||
defer func(){
|
||||
a++
|
||||
}()
|
||||
a, b = y()
|
||||
return
|
||||
}
|
||||
|
||||
func x2() (a int, b bool) {
|
||||
defer func(){
|
||||
a++
|
||||
}()
|
||||
return y()
|
||||
}
|
||||
|
||||
func y() (int, bool) {
|
||||
return 4, false
|
||||
}
|
||||
|
||||
func main() {
|
||||
if a, _ := x(); a != 5 {
|
||||
println("BUG", a)
|
||||
}
|
||||
if a, _ := x2(); a != 5 {
|
||||
println("BUG", a)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user