[llvm] [AArch64][WinCFI] Fix a crash due to missing seh directives (PR #123993)

Hiroshi Yamauchi via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 22 11:41:37 PST 2025


================
@@ -1513,16 +1506,27 @@ static MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec(
       CSStackSizeInc > MaxOffset * (int64_t)Scale.getFixedValue()) {
     // If we are destroying the frame, make sure we add the increment after the
     // last frame operation.
-    if (FrameFlag == MachineInstr::FrameDestroy)
+    if (FrameFlag == MachineInstr::FrameDestroy) {
       ++MBBI;
+      // Also skip the SEH instruction, if needed
+      if (NeedsWinCFI && AArch64InstrInfo::isSEHInstruction(*MBBI))
+          ++MBBI;
+    }
     emitFrameOffset(MBB, MBBI, DL, AArch64::SP, AArch64::SP,
                     StackOffset::getFixed(CSStackSizeInc), TII, FrameFlag,
-                    false, false, nullptr, EmitCFI,
+                    false, NeedsWinCFI, HasWinCFI, EmitCFI,
                     StackOffset::getFixed(CFAOffset));
 
     return std::prev(MBBI);
   }
 
+  // Get rid of the SEH code associated with the old instruction.
----------------
hjyamauchi wrote:

This seh removing code needed to be moved past the above if statement which early returns because it would otherwise leave the seh removed but not one readded and cause a missing seh crash.

https://github.com/llvm/llvm-project/pull/123993


More information about the llvm-commits mailing list