From 5dfc207c5352e606e20399d9e15b2ade2922c0d2 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Mon, 17 Aug 2020 18:16:08 -0500 Subject: [PATCH] [Attributor][FIX] Do not request an AANonNull for non-pointer types --- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 12 ++++---- .../Transforms/Attributor/undefined_behavior.ll | 34 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 958e208..2e8d3f6 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(V)) { FoundUB = true; } else { - auto &NonNullAA = A.getAAFor( - *this, IRPosition::returned(*getAnchorScope())); - if (NonNullAA.isKnownNonNull() && isa(V)) - FoundUB = true; + if (isa(V)) { + auto &NonNullAA = A.getAAFor( + *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 498b683..1c99488 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 +} -- 2.7.4