diff --git a/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp b/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp index f903b225a..12649b6e0 100644 --- a/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp +++ b/FEXCore/Source/Interface/IR/Passes/x87StackOptimizationPass.cpp @@ -733,6 +733,7 @@ void X87StackOptimization::Run(IREmitter* Emit) { // The optimization should run per-block Reset(); + IREmit->SetCurrentCodeBlock(BlockNode); for (auto [CodeNode, IROp] : CurrentIR.GetCode(BlockNode)) { if (!LoweredX87(IROp->Op)) { continue; diff --git a/unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm b/unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm new file mode 100644 index 000000000..8ba933fcf --- /dev/null +++ b/unittests/ASM/FEX_bugs/issue5084_crossblock_const.asm @@ -0,0 +1,31 @@ +%ifdef CONFIG +{ + "RegData": { + "RAX": "0x0" + } +} +%endif + +; Regression test for issue 5084 +; This test was mostly reverse engineered from the IR in 5084. +; Failed with '-n 500 -m' with the error message: +; %51: Arg[0] references invalid %24 + +mov rax, 0 +mov rbx, 0xe0000000 +mov rcx, 1 + +test rcx, rcx +jnz .late_target + +.fallthrough: +fld1 +fstp tword [rbx + 0x1234] +mov rax, 0 +hlt + +.late_target: +fld1 +fstp tword [rbx + 0x1234] +mov rax, 0 +hlt