================
@@ -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:

I checked something that sharpens it further: the three other callers of 
`callsFunctionThatReturnsTwice()` (CFGuardLongjmp.cpp, 
TailRecursionElimination.cpp, ObjCARCContract.cpp) each call it exactly once 
per function-pass invocation, not in a per-query hot loop. So they were never 
actually paying the cost the attribute was meant to solve. The only hot caller 
is `EarliestEscapeAnalysis`, which already caches other per-function state 
(EarliestEscapes, Inst2Obj) - a lazily computed cached bool there would give 
the same O(1) win with none of the Clang/Attributes.td/bitcode/CodeExtractor 
surface.

@nikic @efriedma-quic @hubert-reinterpretcast - since the 
`contains_returns_twice_call` direction came out of our discussion, wanted to 
get your read before reworking: keep the attribute as-is (it does buy 
amortization across pass runs, at the cost of the wider surface above), or 
switch to the EEA local cache? 

https://github.com/llvm/llvm-project/pull/212297
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to