Skip to content

Commit

Permalink
Handle CF_BOOL_NEGATE in simplify_cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
Akuli committed Dec 26, 2023
1 parent 075ea5c commit babd9fe
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/simplify_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ static void update_statuses_with_instruction(const CfGraph *cfg, enum VarStatus
statuses[find_var_index(cfg, ins->operands[0])] = VS_UNPREDICTABLE;
statuses[destidx] = VS_DEFINED;
break;
case CF_BOOL_NEGATE:
switch(statuses[find_var_index(cfg, ins->operands[0])]) {
case VS_TRUE:
statuses[destidx] = VS_FALSE;
break;
case VS_FALSE:
statuses[destidx] = VS_TRUE;
break;
default:
statuses[destidx] = VS_DEFINED;
break;
}
break;
case CF_CONSTANT:
if (ins->data.constant.kind == CONSTANT_BOOL)
statuses[destidx] = ins->data.constant.data.boolean ? VS_TRUE : VS_FALSE;
Expand Down
5 changes: 5 additions & 0 deletions tests/should_succeed/unreachable_warning.jou
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ def lots_of_unreachable_code() -> None:
puts("blah")
i = i+1

def with_not() -> None:
if not True:
puts("Hello") # Warning: this code will never run

def main() -> int:
after_return()
with_not()
# Can't run infinite loops (test script redirects output to file)
return 0

0 comments on commit babd9fe

Please sign in to comment.