[llvm] [LVI] Handle nonnull attributes at callsite (PR #125377)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 2 00:51:08 PST 2025
================
@@ -780,12 +780,25 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
}
if (BBLV.isOverdefined()) {
- // Check whether we're checking at the terminator, and the pointer has
- // been dereferenced in this block.
- PointerType *PTy = dyn_cast<PointerType>(Val->getType());
- if (PTy && BB->getTerminator() == BBI &&
- isNonNullAtEndOfBlock(Val, BB))
- BBLV = ValueLatticeElement::getNot(ConstantPointerNull::get(PTy));
+ if (PointerType *PTy = dyn_cast<PointerType>(Val->getType())) {
+ // Check whether we're checking at the terminator, and the pointer has
+ // been dereferenced in this block.
+ if (BB->getTerminator() == BBI && isNonNullAtEndOfBlock(Val, BB))
+ BBLV = ValueLatticeElement::getNot(ConstantPointerNull::get(PTy));
+ else {
+ for (Use &U : Val->uses()) {
+ if (auto *CB = dyn_cast<CallBase>(U.getUser())) {
+ if (CB->isArgOperand(&U) &&
+ CB->paramHasNonNullAttr(CB->getArgOperandNo(&U),
+ /*AllowUndefOrPoison=*/false) &&
+ isValidAssumeForContext(CB, BBI)) {
+ BBLV = ValueLatticeElement::getNot(ConstantPointerNull::get(PTy));
+ break;
+ }
+ }
+ }
+ }
+ }
----------------
nikic wrote:
This should be in be handled as part of AddNonNullPointersByInstruction: https://github.com/llvm/llvm-project/blob/c3bacf06324b96fb5d48c781b723a29c0e2cf4ca/llvm/lib/Analysis/LazyValueInfo.cpp#L631.
https://github.com/llvm/llvm-project/pull/125377
More information about the llvm-commits
mailing list