Skip to content

Commit

Permalink
Insert extra braces to handle 'else if' without an 'else' correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon committed Oct 3, 2024
1 parent efb5e7d commit de3b86c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 37 deletions.
22 changes: 12 additions & 10 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions Python/optimizer_bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,11 +802,9 @@ dummy_func(void) {
assert(value != NULL);
eliminate_pop_guard(this_instr, !Py_IsNone(value));
}
else {
if (sym_has_type(flag)) {
assert(!sym_matches_type(flag, &_PyNone_Type));
eliminate_pop_guard(this_instr, true);
}
else if (sym_has_type(flag)) {
assert(!sym_matches_type(flag, &_PyNone_Type));
eliminate_pop_guard(this_instr, true);
}
}

Expand All @@ -816,11 +814,9 @@ dummy_func(void) {
assert(value != NULL);
eliminate_pop_guard(this_instr, Py_IsNone(value));
}
else {
if (sym_has_type(flag)) {
assert(!sym_matches_type(flag, &_PyNone_Type));
eliminate_pop_guard(this_instr, false);
}
else if (sym_has_type(flag)) {
assert(!sym_matches_type(flag, &_PyNone_Type));
eliminate_pop_guard(this_instr, false);
}
}

Expand Down
8 changes: 5 additions & 3 deletions Python/optimizer_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,12 @@ def _emit_if(
self.emit(next(tkn_iter))
maybe_if = tkn_iter.peek()
if maybe_if and maybe_if.kind == "IF":
#Emit extra braces around the if to get scoping right
self.emit(" {\n")
self.emit(next(tkn_iter))
else_reachable, rbrace, else_storage = self._emit_if(tkn_iter, uop, storage, inst)
self.out.start_line()
self.emit("}\n")
else:
else_reachable, rbrace, else_storage = self._emit_block(tkn_iter, uop, storage, inst, True)
if not reachable:
Expand Down

0 comments on commit de3b86c

Please sign in to comment.