mirror of
https://github.com/golang/go
synced 2024-11-22 00:54:43 -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)
|
if(pret)
|
||||||
patch(pret, pc);
|
patch(pret, pc);
|
||||||
|
if(hasdefer)
|
||||||
|
ginscall(deferreturn, 0);
|
||||||
if(curfn->exit)
|
if(curfn->exit)
|
||||||
genlist(curfn->exit);
|
genlist(curfn->exit);
|
||||||
if(nerrors != 0)
|
if(nerrors != 0)
|
||||||
goto ret;
|
goto ret;
|
||||||
if(hasdefer)
|
|
||||||
ginscall(deferreturn, 0);
|
|
||||||
pc->as = ARET; // overwrite AEND
|
pc->as = ARET; // overwrite AEND
|
||||||
pc->lineno = lineno;
|
pc->lineno = lineno;
|
||||||
|
|
||||||
|
@ -90,13 +90,13 @@ compile(Node *fn)
|
|||||||
if(pret)
|
if(pret)
|
||||||
patch(pret, pc);
|
patch(pret, pc);
|
||||||
ginit();
|
ginit();
|
||||||
|
if(hasdefer)
|
||||||
|
ginscall(deferreturn, 0);
|
||||||
if(curfn->exit)
|
if(curfn->exit)
|
||||||
genlist(curfn->exit);
|
genlist(curfn->exit);
|
||||||
gclean();
|
gclean();
|
||||||
if(nerrors != 0)
|
if(nerrors != 0)
|
||||||
goto ret;
|
goto ret;
|
||||||
if(hasdefer)
|
|
||||||
ginscall(deferreturn, 0);
|
|
||||||
pc->as = ARET; // overwrite AEND
|
pc->as = ARET; // overwrite AEND
|
||||||
pc->lineno = lineno;
|
pc->lineno = lineno;
|
||||||
|
|
||||||
|
@ -92,11 +92,6 @@ compile(Node *fn)
|
|||||||
if(pret)
|
if(pret)
|
||||||
patch(pret, pc);
|
patch(pret, pc);
|
||||||
ginit();
|
ginit();
|
||||||
if(curfn->exit)
|
|
||||||
genlist(curfn->exit);
|
|
||||||
gclean();
|
|
||||||
if(nerrors != 0)
|
|
||||||
goto ret;
|
|
||||||
if(hasdefer) {
|
if(hasdefer) {
|
||||||
// On Native client, insert call to no-op function
|
// On Native client, insert call to no-op function
|
||||||
// to force alignment immediately before call to deferreturn,
|
// to force alignment immediately before call to deferreturn,
|
||||||
@ -107,6 +102,11 @@ compile(Node *fn)
|
|||||||
ginscall(naclnop, 0);
|
ginscall(naclnop, 0);
|
||||||
ginscall(deferreturn, 0);
|
ginscall(deferreturn, 0);
|
||||||
}
|
}
|
||||||
|
if(curfn->exit)
|
||||||
|
genlist(curfn->exit);
|
||||||
|
gclean();
|
||||||
|
if(nerrors != 0)
|
||||||
|
goto ret;
|
||||||
pc->as = ARET; // overwrite AEND
|
pc->as = ARET; // overwrite AEND
|
||||||
pc->lineno = lineno;
|
pc->lineno = lineno;
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ walkstmt(Node **np)
|
|||||||
NodeList *init;
|
NodeList *init;
|
||||||
NodeList *ll, *rl;
|
NodeList *ll, *rl;
|
||||||
int cl, lno;
|
int cl, lno;
|
||||||
Node *n;
|
Node *n, *f;
|
||||||
|
|
||||||
n = *np;
|
n = *np;
|
||||||
if(n == N)
|
if(n == N)
|
||||||
@ -492,6 +492,14 @@ walkstmt(Node **np)
|
|||||||
n->list = nil;
|
n->list = nil;
|
||||||
break;
|
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);
|
ll = ascompatee(n->op, rl, n->list, &n->ninit);
|
||||||
n->list = reorder3(ll);
|
n->list = reorder3(ll);
|
||||||
break;
|
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