diff options
-rw-r--r-- | llvm/include/llvm/Transforms/IPO/Attributor.h | 16 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/Attributor.cpp | 5 | ||||
-rw-r--r-- | llvm/test/Transforms/FunctionAttrs/nonnull.ll | 24 |
3 files changed, 36 insertions, 9 deletions
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index ba9ec25dec1..2cc9b5fedf2 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -913,15 +913,23 @@ private: // Use the static create method. auto &AA = AAType::createForPosition(IRP, *this); registerAA(AA); - AA.initialize(*this); + + // For now we ignore naked and optnone functions. + bool Invalidate = Whitelist && !Whitelist->count(&AAType::ID); + if (const Function *Fn = IRP.getAnchorScope()) + Invalidate |= Fn->hasFnAttribute(Attribute::Naked) || + Fn->hasFnAttribute(Attribute::OptimizeNone); // Bootstrap the new attribute with an initial update to propagate // information, e.g., function -> call site. If it is not on a given // whitelist we will not perform updates at all. - if (Whitelist && !Whitelist->count(&AAType::ID)) + if (Invalidate) { AA.getState().indicatePessimisticFixpoint(); - else - AA.update(*this); + return AA; + } + + AA.initialize(*this); + AA.update(*this); if (TrackDependence && AA.getState().isValidState()) QueryMap[&AA].insert(const_cast<AbstractAttribute *>(QueryingAA)); diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 787a36cb60c..eb6756c53e7 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -4847,11 +4847,6 @@ static bool runAttributorOnModule(Module &M, AnalysisGetter &AG) { else NumFnWithoutExactDefinition++; - // For now we ignore naked and optnone functions. - if (F.hasFnAttribute(Attribute::Naked) || - F.hasFnAttribute(Attribute::OptimizeNone)) - continue; - // We look at internal functions only on-demand but if any use is not a // direct call, we have to do it eagerly. if (F.hasLocalLinkage()) { diff --git a/llvm/test/Transforms/FunctionAttrs/nonnull.ll b/llvm/test/Transforms/FunctionAttrs/nonnull.ll index 63b2380a7fc..7e7b1ad2143 100644 --- a/llvm/test/Transforms/FunctionAttrs/nonnull.ll +++ b/llvm/test/Transforms/FunctionAttrs/nonnull.ll @@ -545,6 +545,30 @@ define weak_odr void @weak_caller(i32* nonnull %a) { ret void } +; Expect nonnull +; ATTRIBUTOR: define internal void @control(i32* nocapture nonnull readnone align 16 dereferenceable(8) %a) +define internal void @control(i32* dereferenceable(4) %a) { + call void @use_i32_ptr(i32* %a) + ret void +} +; Avoid nonnull as we do not touch naked functions +; ATTRIBUTOR: define internal void @naked(i32* dereferenceable(4) %a) +define internal void @naked(i32* dereferenceable(4) %a) naked { + call void @use_i32_ptr(i32* %a) + ret void +} +; Avoid nonnull as we do not touch optnone +; ATTRIBUTOR: define internal void @optnone(i32* dereferenceable(4) %a) +define internal void @optnone(i32* dereferenceable(4) %a) optnone noinline { + call void @use_i32_ptr(i32* %a) + ret void +} +define void @make_live(i32* nonnull dereferenceable(8) %a) { + call void @naked(i32* nonnull dereferenceable(8) align 16 %a) + call void @control(i32* nonnull dereferenceable(8) align 16 %a) + call void @optnone(i32* nonnull dereferenceable(8) align 16 %a) + ret void +} attributes #0 = { "null-pointer-is-valid"="true" } attributes #1 = { nounwind willreturn} |