[Attributor] Ignore illegal accesses to `null`
authorJohannes Doerfert <johannes@jdoerfert.de>
Sun, 10 May 2020 21:53:07 +0000 (16:53 -0500)
committerJohannes Doerfert <johannes@jdoerfert.de>
Mon, 11 May 2020 00:06:10 +0000 (19:06 -0500)
When we categorize a pointer value we bailed at `null` before. If we
know `null` is not a valid memory location we can ignore it as there
won't be an access at all.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

index b3f656d..26196f0 100644 (file)
@@ -6229,9 +6229,13 @@ void AAMemoryLocationImpl::categorizePtrValue(
         MLK = NO_GLOBAL_INTERNAL_MEM;
       else
         MLK = NO_GLOBAL_EXTERNAL_MEM;
-    } else if (isa<AllocaInst>(V))
+    } else if (isa<ConstantPointerNull>(V) &&
+               !NullPointerIsDefined(getAssociatedFunction(),
+                                     V.getType()->getPointerAddressSpace())) {
+      return true;
+    } else if (isa<AllocaInst>(V)) {
       MLK = NO_LOCAL_MEM;
-    else if (const auto *CB = dyn_cast<CallBase>(&V)) {
+    else if (const auto *CB = dyn_cast<CallBase>(&V)) {
       const auto &NoAliasAA =
           A.getAAFor<AANoAlias>(*this, IRPosition::callsite_returned(*CB));
       if (NoAliasAA.isAssumedNoAlias())