From babd9fefa58479f9e3a1c2457cc56c1875dd2b66 Mon Sep 17 00:00:00 2001 From: Akuli Date: Tue, 26 Dec 2023 17:26:09 +0200 Subject: [PATCH] Handle CF_BOOL_NEGATE in simplify_cfg --- src/simplify_cfg.c | 13 +++++++++++++ tests/should_succeed/unreachable_warning.jou | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/simplify_cfg.c b/src/simplify_cfg.c index ad22b55e..6d89e572 100644 --- a/src/simplify_cfg.c +++ b/src/simplify_cfg.c @@ -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; diff --git a/tests/should_succeed/unreachable_warning.jou b/tests/should_succeed/unreachable_warning.jou index 116ac47d..f180a364 100644 --- a/tests/should_succeed/unreachable_warning.jou +++ b/tests/should_succeed/unreachable_warning.jou @@ -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