Then clause needs pop for stack consistency

e$B1sF#$H?=$7$^$9!#e(B

e$B0J2<$r<B9T$9$k$H0l2sL$N%k!<%W$N=PNO$@$1JQ$K$J$j$^$9!#e(B

$ ./ruby -e ’
f = true
if false
else
while f
p [:foo, while true; break :bar; end]
redo
end
end
’ | head
[:bar, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]
[:foo, :bar]

NODE_IF e$B$N%3%s%Q%$%k$G!"e(Bthen e$B@a$N:G8e$Ne(B jump e$B$N8e$Ge(B
stack consistency e$B$re(B
e$BJ]$D$?$a$Ne(B pop e$B$,I,MW$G$9!#e(B

Index: compile.c

— compile.c (revision 14784)
+++ compile.c (working copy)
@@ -2634,6 +2634,7 @@
ADD_LABEL(ret, then_label);
ADD_SEQ(ret, then_seq);
ADD_INSNL(ret, nd_line(node), jump, end_label);

  • if(!poped) ADD_INSN(ret, nd_line(node), pop);

    ADD_LABEL(ret, else_label);
    ADD_SEQ(ret, else_seq);

e$B1sF#$G$9!#e(B

NODE_WHEN e$B$K$bF1$8LdBj$,$"$j$^$7$?!#0J2<$Ne(B 2
e$B$D$N%W%m%0%i%`$O0l2sL$@$1e(B
[:foo, :bar] e$B$G$J$$$b$N$r=PNO$7$^$9!#e(B

f = true
case
when false
when true
while f
p [:foo, while true; break :bar; end]
redo
end
end

f = true
case
when true
while f
p [:foo, while true; break :bar; end]
redo
end
end

NODE_CASE e$B$K$bF1MM$NLdBj$,$"$j$^$9$,!"$=$l$>$l$Ne(B body
e$B$N:G=i$Ke(B pop e$B$,e(B
e$BA^F~$5$l$k$?$a!"GA$-7j:GE,2=$,F/$+$:!"H/>I$9$kNc$O8+$D$1$i$l$F$$$^$;$s!#e(B
e$B$G$b$9$4$/%P%0$N85$J$N$G!“0J2<$N%Q%C%A$G$Oe(B NODE_CASE
e$B$bBP=h$7$F$”$j$^$9!#e(B

Index: compile.c

— compile.c (revision 14785)
+++ compile.c (working copy)
@@ -2634,6 +2634,7 @@
ADD_LABEL(ret, then_label);
ADD_SEQ(ret, then_seq);
ADD_INSNL(ret, nd_line(node), jump, end_label);

  • if (!poped) ADD_INSN(ret, nd_line(node), pop);

    ADD_LABEL(ret, else_label);
    ADD_SEQ(ret, else_seq);
    @@ -2680,6 +2681,7 @@
    ADD_INSN(body_seq, nd_line(node), pop);
    COMPILE_(body_seq, “when body”, node->nd_body, poped);
    ADD_INSNL(body_seq, nd_line(node), jump, endlabel);

  •  if (!poped) ADD_INSN(body_seq, nd_line(node), pop);
    
     vals = node->nd_head;
     if (vals) {
    

@@ -2723,6 +2725,7 @@
ADD_INSN(cond_seq, nd_line(node), pop);
COMPILE_(cond_seq, “else”, node, poped);
ADD_INSNL(cond_seq, nd_line(node), jump, endlabel);

  •  if (!poped) ADD_INSN(cond_seq, nd_line(node), pop);
    
    }
    else {
    debugs("== else (implicit)\n");
    @@ -2761,6 +2764,7 @@
    ADD_LABEL(body_seq, l1);
    COMPILE_(body_seq, “when”, node->nd_body, poped);
    ADD_INSNL(body_seq, nd_line(node), jump, endlabel);
  •  if (!poped) ADD_INSN(body_seq, nd_line(node), pop);
    
     vals = node->nd_head;
     if (vals && nd_type(vals) == NODE_ARRAY) {
    

@@ -2803,6 +2807,7 @@
/* else */
COMPILE_(ret, “else”, node, poped);
ADD_INSNL(ret, nd_line(orig_node), jump, endlabel);

  • if (!poped) ADD_INSN(ret, nd_line(orig_node), pop);

    ADD_SEQ(ret, body_seq);
    ADD_LABEL(ret, endlabel);

e$B$D$$$G$G$9$,!"?tL>$NJ}$+$i%3%_%C%H8"8B$r;}$C$?$i$I$&$+$H8@$o$l$F$$$^$9!#e(B
e$B$h$1$l$P!"$*0l$D$/$@$5$$!#Js9p$7$?$b$N$re(B test_knownbug.rb
e$B$K>!<j$Ke(B
e$BDI2C$9$k$/$i$$$O$G$-$k$H;W$$$^$9!#e(B

e$B1sF#$G$9!#e(B

e$B2?EY$b$9$_$^$;$s!#e(B

07/12/30 e$B$Ke(B Yusuke ENDOH[email protected] e$B$5$s$O=q$-$^$7$?e(B:

NODE_CASE e$B$K$bF1MM$NLdBj$,$“$j$^$9$,!”$=$l$>$l$Ne(B body e$B$N:G=i$Ke(B pop e$B$,e(B
e$BA^F~$5$l$k$?$a!"GA$-7j:GE,2=$,F/$+$:!"H/>I$9$kNc$O8+$D$1$i$l$F$$$^$;$s!#e(B
e$B$G$b$9$4$/%P%0$N85$J$N$G!“0J2<$N%Q%C%A$G$Oe(B NODE_CASE e$B$bBP=h$7$F$”$j$^$9!#e(B

NODE_CASE
e$B$NBP1~$,4V0c$C$F$$$^$7$?>e$KH4$1$,$“$j$^$7$?!#$9$_$^$;$s!#e(B
NODE_CASE e$B$Ne(B NODE_WHEN e$B$?$A$O$=$l$>$l$,e(B pop
e$B$9$k$N$G!”$=$N:G8e$K$Oe(B putnil e$B$re(B
e$BB-$5$J$$$H$$$1$^$;$s$G$7$?!#e(B
e$B:#$N$H$3$mH/>I$O$7$J$$$N$GJ|$C$F$*$/$N$b<j$+$b$7$l$^$;$s!#e(B

Index: compile.c

— compile.c (revision 14785)
+++ compile.c (working copy)
@@ -2634,6 +2634,7 @@
ADD_LABEL(ret, then_label);
ADD_SEQ(ret, then_seq);
ADD_INSNL(ret, nd_line(node), jump, end_label);

  • if (!poped) ADD_INSN(ret, nd_line(node), pop);

    ADD_LABEL(ret, else_label);
    ADD_SEQ(ret, else_seq);
    @@ -2680,6 +2681,7 @@
    ADD_INSN(body_seq, nd_line(node), pop);
    COMPILE_(body_seq, “when body”, node->nd_body, poped);
    ADD_INSNL(body_seq, nd_line(node), jump, endlabel);

  •  if (poped) ADD_INSN(body_seq, nd_line(node), putnil);
    
     vals = node->nd_head;
     if (vals) {
    

@@ -2723,6 +2725,7 @@
ADD_INSN(cond_seq, nd_line(node), pop);
COMPILE_(cond_seq, “else”, node, poped);
ADD_INSNL(cond_seq, nd_line(node), jump, endlabel);

  •  if (poped) ADD_INSN(cond_seq, nd_line(node), putnil);
    

    }
    else {
    debugs(“== else (implicit)\n”);
    @@ -2732,6 +2735,7 @@
    ADD_INSN(cond_seq, nd_line(tempnode), putnil);
    }
    ADD_INSNL(cond_seq, nd_line(tempnode), jump, endlabel);

  •  if (poped) ADD_INSN(cond_seq, nd_line(tempnode), putnil);
    

    }

    if (special_literals) {
    @@ -2761,6 +2765,7 @@
    ADD_LABEL(body_seq, l1);
    COMPILE_(body_seq, “when”, node->nd_body, poped);
    ADD_INSNL(body_seq, nd_line(node), jump, endlabel);

  •  if (!poped) ADD_INSN(body_seq, nd_line(node), pop);
    
     vals = node->nd_head;
     if (vals && nd_type(vals) == NODE_ARRAY) {
    

@@ -2803,6 +2808,7 @@
/* else */
COMPILE_(ret, “else”, node, poped);
ADD_INSNL(ret, nd_line(orig_node), jump, endlabel);

  • if (!poped) ADD_INSN(ret, nd_line(orig_node), pop);

    ADD_SEQ(ret, body_seq);
    ADD_LABEL(ret, endlabel);