[clang] [llvm] [CaptureTracking][FunctionAttrs] Add support for CaptureInfo (PR #125880)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 7 07:42:12 PST 2025


================
@@ -438,18 +445,28 @@ void llvm::PointerMayBeCaptured(const Value *V, CaptureTracker *Tracker,
   };
   while (!Worklist.empty()) {
     const Use *U = Worklist.pop_back_val();
-    switch (DetermineUseCaptureKind(*U, IsDereferenceableOrNull)) {
-    case UseCaptureKind::NO_CAPTURE:
+    CaptureInfo CI = DetermineUseCaptureKind(*U, IsDereferenceableOrNull);
+    if (capturesNothing(CI))
       continue;
-    case UseCaptureKind::MAY_CAPTURE:
-      if (Tracker->captured(U))
+    CaptureComponents OtherCC = CI.getOtherComponents();
+    CaptureComponents RetCC = CI.getRetComponents();
+    if (capturesAnything(OtherCC)) {
+      switch (Tracker->captured(U, CI)) {
+      case CaptureTracker::Stop:
         return;
-      continue;
-    case UseCaptureKind::PASSTHROUGH:
-      if (!AddUses(U->getUser()))
-        return;
-      continue;
+      case CaptureTracker::ContinueIgnoringReturn:
+        continue;
+      case CaptureTracker::Continue:
+        // Fall through to passthrough handling, but only if RetCC contains
+        // additional components that OtherCC does not.
----------------
nikic wrote:

This is to avoid wasting time by following values that cannot contribute any *new* capture information. For call captures, we'll usually have OtherCC == RetCC, and there's no point in following the return value in that case, as it won't contribute anything new. That would be a regression relative to current CaptureTracking behavior (which doesn't follow call return values).

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


More information about the cfe-commits mailing list