Commit 8c23c1ab authored by Russ Cox's avatar Russ Cox

5g: defer vs optimizer bug

Fixes #1924.

R=ken2
CC=golang-dev
https://golang.org/cl/4802063
parent 3de6228a
......@@ -728,13 +728,19 @@ addsplits(void)
void
addmove(Reg *r, int bn, int rn, int f)
{
Prog *p, *p1;
Prog *p, *p1, *p2;
Adr *a;
Var *v;
p1 = mal(sizeof(*p1));
*p1 = zprog;
p = r->prog;
// If there's a stack fixup coming (after BL newproc or BL deferproc),
// delay the load until after the fixup.
p2 = p->link;
if(p2 && p2->as == AMOVW && p2->from.type == D_CONST && p2->from.reg == REGSP && p2->to.reg == REGSP && p2->to.type == D_REG)
p = p2;
p1->link = p->link;
p->link = p1;
......
package main
import "fmt"
var s string
func accum(args ...interface{}) {
s += fmt.Sprintln(args...)
}
func f(){
v := 0.0
for i := 0; i < 3; i++ {
v += 0.1
defer accum(v)
}
}
func main() {
f()
if s != "0.30000000000000004\n0.2\n0.1\n" {
println("BUG: defer")
print(s)
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment