[clang] [llvm] [BasicAA] Fix miscompilation with setjmp/longjmp due to missing longjmp re-entry paths in alias analysis (PR #212297)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 7 23:05:25 PDT 2026


================
@@ -257,7 +257,17 @@ CaptureComponents EarliestEscapeAnalysis::getCapturesBefore(
       return isNotInCycle(I, &DT, LI, CI);
     }
 
-    return !isPotentiallyReachable(CaptureInst, I, nullptr, &DT, LI, CI);
+    if (isPotentiallyReachable(CaptureInst, I, nullptr, &DT, LI, CI))
+      return false;
+
+    // A `longjmp` may re-enter the function at any `returns_twice` call
+    // (e.g. `setjmp`), If the function contains such a call, conservatively
+    // treat the object as captured.
+    if (DT.getRoot()->getParent()->hasFnAttribute(
+            Attribute::ContainsReturnsTwiceCall))
+      return false;
----------------
midhuncodes7 wrote:

Agreed, reworked the patch to drop `contains_returns_twice_call` and cache the check on `EarliestEscapeAnalysis` instead, reusing the existing `Function::callsFunctionThatReturnsTwice()` scan

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


More information about the cfe-commits mailing list