[clang] [clang][sema] Add nonnull attribute to builtin format functions (PR #158626)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 16 07:33:10 PDT 2025


================
@@ -17097,6 +17097,15 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
       }
     }
 
+    SmallVector<int, 4> Indxs;
+    if (Context.BuiltinInfo.IsNonNull(BuiltinID, Indxs) &&
+        !FD->hasAttr<NonNullAttr>()) {
+      llvm::SmallVector<ParamIdx, 4> ParamIndxs;
+      for (int I : Indxs)
+        ParamIndxs.push_back(ParamIdx(I + 1, FD));
+      FD->addAttr(NonNullAttr::CreateImplicit(Context, ParamIndxs.data(),
+                                              ParamIndxs.size()));
----------------
Sirraide wrote:

Ah, I forgot it requires a decl, in that case that’s fine.

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


More information about the cfe-commits mailing list