From ebdf8d3b3c45473ff83f9b151e2c262199a5de79 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 14 May 2026 16:28:32 +0200 Subject: [PATCH] Mark undef flag functions as memory(none), nounwind, willreturn This allows for dead store elimination of the flags --- src/striga/semantics.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/striga/semantics.py b/src/striga/semantics.py index f56df09..95df9b6 100644 --- a/src/striga/semantics.py +++ b/src/striga/semantics.py @@ -133,10 +133,17 @@ class Semantics: self.call_handler = self.module.add_function("__striga_call", helper_ty) self.ret_handler = self.module.add_function("__striga_ret", helper_ty) self.syscall_handler = self.module.add_function("__striga_syscall", helper_ty) - self.undef_flags = { - name: self.module.add_function(f"__striga_undef_{name}", undef_flag_ty) - for name in FLAGS - } + def add_undef_flag_helper(name: str) -> Function: + helper = self.module.add_function(f"__striga_undef_{name}", undef_flag_ty) + # Undefined-flag helpers model arbitrary values, not side effects. + # Match Remill's symbolic/undefined helper annotations so calls can + # be deleted after their flag stores are proven dead. + helper.attributes.add_memory("none") + helper.attributes.add("nounwind") + helper.attributes.add("willreturn") + return helper + + self.undef_flags = {name: add_undef_flag_helper(name) for name in FLAGS} # Set per function lifted self.insn_blocks: dict[int, BasicBlock] = {}