Closes #11471: avoid generating a JUMP_FORWARD instruction at the end of an if-block if there is no else-clause.
Original patch by Eugene Toder.
diff --git a/Python/compile.c b/Python/compile.c
index 9cc1399..e46ec6c 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1940,7 +1940,7 @@
} else if (constant == 1) {
VISIT_SEQ(c, stmt, s->v.If.body);
} else {
- if (s->v.If.orelse) {
+ if (asdl_seq_LEN(s->v.If.orelse)) {
next = compiler_new_block(c);
if (next == NULL)
return 0;
@@ -1950,8 +1950,8 @@
VISIT(c, expr, s->v.If.test);
ADDOP_JABS(c, POP_JUMP_IF_FALSE, next);
VISIT_SEQ(c, stmt, s->v.If.body);
- ADDOP_JREL(c, JUMP_FORWARD, end);
- if (s->v.If.orelse) {
+ if (asdl_seq_LEN(s->v.If.orelse)) {
+ ADDOP_JREL(c, JUMP_FORWARD, end);
compiler_use_next_block(c, next);
VISIT_SEQ(c, stmt, s->v.If.orelse);
}