Skip to content

Commit

Permalink
GH-125521: Remove if (true) from generated output to reduce C compi…
Browse files Browse the repository at this point in the history
…ler warnings (GH-125700)
  • Loading branch information
markshannon authored Oct 22, 2024
1 parent c1bdbe8 commit 57e3c59
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 40 deletions.
27 changes: 27 additions & 0 deletions Lib/test/test_generated_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,33 @@ def test_push_then_error(self):
"""
self.run_cases_test(input, output)

def test_error_if_true(self):

input = """
inst(OP1, ( --)) {
ERROR_IF(true, here);
}
inst(OP2, ( --)) {
ERROR_IF(1, there);
}
"""
output = """
TARGET(OP1) {
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP1);
goto here;
}
TARGET(OP2) {
frame->instr_ptr = next_instr;
next_instr += 1;
INSTRUCTION_STATS(OP2);
goto there;
}
"""
self.run_cases_test(input, output)

def test_scalar_array_inconsistency(self):

input = """
Expand Down
68 changes: 34 additions & 34 deletions Python/generated_cases.c.h

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

2 changes: 1 addition & 1 deletion Tools/cases_generator/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def always_exits(op: parser.InstDef) -> bool:
if tkn.text == "DEOPT_IF" or tkn.text == "ERROR_IF":
next(tkn_iter) # '('
t = next(tkn_iter)
if t.text == "true":
if t.text in ("true", "1"):
return True
return False

Expand Down
18 changes: 13 additions & 5 deletions Tools/cases_generator/generators_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,24 @@ def error_if(
storage: Storage,
inst: Instruction | None,
) -> bool:
self.out.emit_at("if ", tkn)
lparen = next(tkn_iter)
self.emit(lparen)
assert lparen.kind == "LPAREN"
first_tkn = tkn_iter.peek()
emit_to(self.out, tkn_iter, "COMMA")
unconditional = always_true(first_tkn)
if unconditional:
next(tkn_iter)
comma = next(tkn_iter)
if comma.kind != "COMMA":
raise analysis_error(f"Expected comma, got '{comma.text}'", comma)
self.out.start_line()
else:
self.out.emit_at("if ", tkn)
self.emit(lparen)
emit_to(self.out, tkn_iter, "COMMA")
self.out.emit(") ")
label = next(tkn_iter).text
next(tkn_iter) # RPAREN
next(tkn_iter) # Semi colon
self.out.emit(") ")
storage.clear_inputs("at ERROR_IF")
c_offset = storage.stack.peek_offset()
try:
Expand All @@ -196,7 +204,7 @@ def error_if(
self.out.emit(label)
self.out.emit(";\n")
self.out.emit("}\n")
return not always_true(first_tkn)
return not unconditional

def error_no_pop(
self,
Expand Down

0 comments on commit 57e3c59

Please sign in to comment.