[llvm] 5dfc207 - [Attributor][FIX] Do not request an AANonNull for non-pointer types

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 16:23:41 PDT 2020


Author: Johannes Doerfert
Date: 2020-08-17T18:21:08-05:00
New Revision: 5dfc207c5352e606e20399d9e15b2ade2922c0d2

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

LOG: [Attributor][FIX] Do not request an AANonNull for non-pointer types

Added: 
    

Modified: 
    llvm/lib/Transforms/IPO/AttributorAttributes.cpp
    llvm/test/Transforms/Attributor/undefined_behavior.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 958e20878f3a..2e8d3f6774d5 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -2017,7 +2017,7 @@ struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior {
         if (idx >= Callee->arg_size())
           break;
         Value *ArgVal = CB.getArgOperand(idx);
-        if (!ArgVal)
+        if (!ArgVal || !ArgVal->getType()->isPointerTy())
           continue;
         IRPosition CalleeArgumentIRP =
             IRPosition::argument(*Callee->getArg(idx));
@@ -2068,10 +2068,12 @@ struct AAUndefinedBehaviorImpl : public AAUndefinedBehavior {
           if (isa<UndefValue>(V)) {
             FoundUB = true;
           } else {
-            auto &NonNullAA = A.getAAFor<AANonNull>(
-                *this, IRPosition::returned(*getAnchorScope()));
-            if (NonNullAA.isKnownNonNull() && isa<ConstantPointerNull>(V))
-              FoundUB = true;
+            if (isa<ConstantPointerNull>(V)) {
+              auto &NonNullAA = A.getAAFor<AANonNull>(
+                  *this, IRPosition::returned(*getAnchorScope()));
+              if (NonNullAA.isKnownNonNull())
+                FoundUB = true;
+            }
           }
 
           if (FoundUB)

diff  --git a/llvm/test/Transforms/Attributor/undefined_behavior.ll b/llvm/test/Transforms/Attributor/undefined_behavior.ll
index 498b68361fd8..1c99488ccb31 100644
--- a/llvm/test/Transforms/Attributor/undefined_behavior.ll
+++ b/llvm/test/Transforms/Attributor/undefined_behavior.ll
@@ -1004,3 +1004,37 @@ onone:
 ondefault:
   ret i32* undef
 }
+
+define noundef i32 @returned_nonnnull_noundef_int() {
+; IS__TUNIT____: Function Attrs: nofree nosync nounwind readnone willreturn
+; IS__TUNIT____-LABEL: define {{[^@]+}}@returned_nonnnull_noundef_int()
+; IS__TUNIT____-NEXT:    ret i32 0
+;
+; IS__CGSCC____: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
+; IS__CGSCC____-LABEL: define {{[^@]+}}@returned_nonnnull_noundef_int()
+; IS__CGSCC____-NEXT:    ret i32 0
+;
+  ret i32 0
+}
+
+declare void @callee_int_arg(i32)
+
+define void @callsite_noundef_1() {
+; CHECK-LABEL: define {{[^@]+}}@callsite_noundef_1()
+; CHECK-NEXT:    call void @callee_int_arg(i32 noundef 0)
+; CHECK-NEXT:    ret void
+;
+  call void @callee_int_arg(i32 noundef 0)
+  ret void
+}
+
+declare void @callee_ptr_arg(i32*)
+
+define void @callsite_noundef_2() {
+; CHECK-LABEL: define {{[^@]+}}@callsite_noundef_2()
+; CHECK-NEXT:    call void @callee_ptr_arg(i32* noundef undef)
+; CHECK-NEXT:    ret void
+;
+  call void @callee_ptr_arg(i32* noundef undef)
+  ret void
+}


        


More information about the llvm-commits mailing list