[llvm] [ValueTracking] Handle nonnull attributes at callsite (PR #124908)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 03:43:12 PST 2025


================
@@ -432,6 +432,24 @@ bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
   }
 }
 
+bool CallBase::paramHasNonNullAttr(unsigned ArgNo,
+                                   bool AllowUndefOrPoison) const {
+  assert(getArgOperand(ArgNo)->getType()->isPointerTy() &&
+         "Argument must be a pointer");
+  if (paramHasAttr(ArgNo, Attribute::NonNull) &&
+      (AllowUndefOrPoison || paramHasAttr(ArgNo, Attribute::NoUndef)))
+    return true;
+
+  Attribute Attr = getParamAttr(ArgNo, Attribute::Dereferenceable);
----------------
nikic wrote:

We already have a getParamDereferenceableBytes API. I think it would make sense to change it to also fall back to the callee and use it here.

https://github.com/llvm/llvm-project/pull/124908


More information about the llvm-commits mailing list