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

Antonio Frighetto via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 16 02:15:33 PDT 2026


================
@@ -192,6 +192,14 @@ class LLVM_ABI EarliestEscapeAnalysis final : public CaptureAnalysis {
   /// This is used for cache invalidation purposes.
   DenseMap<Instruction *, TinyPtrVector<const Value *>> Inst2Obj;
 
+  /// Whether the function contains a call to a function that may return
+  /// twice (e.g. setjmp). Lazily computed and cached, since a `longjmp` may
+  /// re-enter the function at any such call, which this analysis needs to
+  /// account for conservatively.
+  std::optional<bool> ContainsReturnsTwiceCall;
+
+  bool containsReturnsTwiceCall();
----------------
antoniofrighetto wrote:

```suggestion
  /// Cached result of Function::callsFunctionThatReturnsTwice(), used to
  /// account for longjmp re-entry paths not visibile to the forward CFG.
  std::optional<bool> CallsReturnsTwiceFn;

  /// Whether the function contains a call that may return twice (e.g., setjmp).
  bool callsReturnsTwiceFn();
```

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


More information about the cfe-commits mailing list