[llvm] c2ed0b1 - [CaptureTracking] Remove allocator comparison special case (#201143)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 00:52:20 PDT 2026


Author: Nikita Popov
Date: 2026-06-03T09:52:15+02:00
New Revision: c2ed0b1d825d7c75ca15b57812767ec3858c60db

URL: https://github.com/llvm/llvm-project/commit/c2ed0b1d825d7c75ca15b57812767ec3858c60db
DIFF: https://github.com/llvm/llvm-project/commit/c2ed0b1d825d7c75ca15b57812767ec3858c60db.diff

LOG: [CaptureTracking] Remove allocator comparison special case (#201143)

CaptureTracking had a special case that (incorrectly) reported
`captures(none)` for comparisons of allocation functions with null.
Remove this special case and return the correct
`captures(address_is_null)` result instead.

It seems like this doesn't have any practical benefit anymore, as things
like AA will ignore address-only captures nowadays.

Added: 
    

Modified: 
    llvm/lib/Analysis/CaptureTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index b5ee2430796cf..e1aa06b8eafc8 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -372,23 +372,11 @@ UseCaptureInfo llvm::DetermineUseCaptureKind(const Use &U, const Value *Base) {
   case Instruction::ICmp: {
     unsigned Idx = U.getOperandNo();
     unsigned OtherIdx = 1 - Idx;
+    // Check whether this is a comparison of the base pointer against
+    // null.
     if (isa<ConstantPointerNull>(I->getOperand(OtherIdx)) &&
-        cast<ICmpInst>(I)->isEquality()) {
-      // TODO(captures): Remove these special cases once we make use of
-      // captures(address_is_null).
-
-      // Don't count comparisons of a no-alias return value against null as
-      // captures. This allows us to ignore comparisons of malloc results
-      // with null, for example.
-      if (U->getType()->getPointerAddressSpace() == 0)
-        if (isNoAliasCall(U.get()->stripPointerCasts()))
-          return CaptureComponents::None;
-
-      // Check whether this is a comparison of the base pointer against
-      // null.
-      if (U.get() == Base)
-        return CaptureComponents::AddressIsNull;
-    }
+        cast<ICmpInst>(I)->isEquality() && U.get() == Base)
+      return CaptureComponents::AddressIsNull;
 
     // Otherwise, be conservative. There are crazy ways to capture pointers
     // using comparisons. However, only the address is captured, not the


        


More information about the llvm-commits mailing list