Fix bug with uninitialized MONITOR variable causing UB

This commit is contained in:
Duncan Ogilvie
2025-11-05 20:46:01 -05:00
committed by Kyle Elliott
parent eba0652f86
commit 6082054723
+5 -1
View File
@@ -758,7 +758,11 @@ void Arch::InitializeEmptyLiftedFunction(llvm::Function *func) const {
llvm::IRBuilder<> ir(block);
ir.CreateAlloca(u8, nullptr, "BRANCH_TAKEN");
ir.CreateAlloca(addr, nullptr, "RETURN_PC");
ir.CreateAlloca(addr, nullptr, "MONITOR");
// NOTE: we need to start with an initialize MONITOR state,
// otherwise STLXR without a preceding LDXR/LDAXR will do UB
auto monitor = ir.CreateAlloca(addr, nullptr, "MONITOR");
ir.CreateStore(llvm::ConstantInt::get(addr, 0), monitor);
// NOTE(pag): `PC` and `NEXT_PC` are handled by
// `FinishLiftedFunctionInitialization`.