[llvm] [WinEH] Emit state stores before SEH scopes (PR #116546)

Maurice Heumann via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 17 06:55:36 PST 2024


https://github.com/momo5502 created https://github.com/llvm/llvm-project/pull/116546

This is a draft. There is more to come. I assume things are still broken as state needs to be restored after the scopes.

This fixes #90946

>From 9f371c24d6f1f8e28978f671acef8dfa89e26a4a Mon Sep 17 00:00:00 2001
From: momo5502 <mauriceheumann at gmail.com>
Date: Sun, 17 Nov 2024 15:52:01 +0100
Subject: [PATCH] [WinEH] Emit state stores before SEH scopes

---
 llvm/lib/Target/X86/X86WinEHState.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp
index ef212736730114..f273e997c15cc9 100644
--- a/llvm/lib/Target/X86/X86WinEHState.cpp
+++ b/llvm/lib/Target/X86/X86WinEHState.cpp
@@ -604,8 +604,19 @@ static int getSuccState(DenseMap<BasicBlock *, int> &InitialStates, Function &F,
   return CommonState;
 }
 
+static bool isSehScopeBegin(const CallBase &Call) {
+  const Function *CF = Call.getCalledFunction();
+  return CF
+         && CF->isIntrinsic()
+         && CF->getIntrinsicID() == Intrinsic::seh_scope_begin;
+}
+
 bool WinEHStatePass::isStateStoreNeeded(EHPersonality Personality,
                                         CallBase &Call) {
+  if (isSehScopeBegin(Call)) {
+    return true;
+  }
+
   // If the function touches memory, it needs a state store.
   if (isAsynchronousEHPersonality(Personality))
     return !Call.doesNotAccessMemory();



More information about the llvm-commits mailing list