[clang] [NFC][clang] Quote literal builtin attribute markers in Builtins.def docs (PR #160080)

2025-09-22 Thread Radovan Božić via cfe-commits
bozicrHT wrote: I noticed the comment: ``` // This is only documentation for the database layout. This will be removed once all builtin databases are converted to tablegen files ``` Since it seems that not all builtins are converted yet, would it be clearer to use a less common letter (e.g. `

[clang] [NFC][clang] Quote literal builtin attribute markers in Builtins.def docs (PR #160080)

2025-09-22 Thread Radovan Božić via cfe-commits
bozicrHT wrote: > > I noticed the comment: > > ``` > > // This is only documentation for the database layout. This will be removed > > once all builtin databases are converted to tablegen files > > ``` > > > > > > > > > > > > > > > > > > > > > > > > Sin

[clang] [NFC][clang] Quote literal builtin attribute markers in Builtins.def docs (PR #160080)

2025-09-22 Thread Radovan Božić via cfe-commits
bozicrHT wrote: > > > But I'm not sure what we could use reasonably. > > > > > > We could replace it w/ e.g. `*` and add a note along the lines of ‘where > > `*` is any integer/index/whatever it’s actually supposed to be’ > > Asterisk seems pretty overloaded here... maybe the same except with

[clang] [NFC][clang] Quote literal builtin attribute markers in Builtins.def docs (PR #160080)

2025-09-22 Thread Radovan Božić via cfe-commits
https://github.com/bozicrHT created https://github.com/llvm/llvm-project/pull/160080 Clarify the documentation in Builtins.def by quoting literal attribute markers (e.g. 'n', 'r', 'U', 'N') to distinguish them from placeholders such as N in C. This avoids confusion and makes the attribute docs

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

2025-09-22 Thread Radovan Božić via cfe-commits
@@ -67,6 +67,7 @@ // The third value provided to the macro specifies information about attributes // of the function. These must be kept in sync with the predicates in the // Builtin::Context class. Currently we have: +// N -> nonnull bozicrHT wrote: I went

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

2025-09-22 Thread Radovan Božić via cfe-commits
@@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wnonnull -Wno-format-security %s + +#include +#include + +typedef struct _FILE FILE; + +int printf(char const* restrict, ...); +int __builtin_printf(char const* restrict, ...); +int fprintf(FILE* restrict, char const* r

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

2025-09-17 Thread Radovan Božić via cfe-commits
@@ -392,6 +392,10 @@ class Context { bool performsCallback(unsigned ID, llvm::SmallVectorImpl &Encoding) const; + /// Return true if this builtin has parameters at fixed positions + /// that must be non-null. + bool IsNonNull(unsigned ID, llvm::Sma

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

2025-09-17 Thread Radovan Božić via cfe-commits
@@ -0,0 +1,74 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -Wnonnull -Wno-format-security %s + +#include +#include bozicrHT wrote: Thanks for the heads-up! https://github.com/llvm/llvm-project/pull/158626 ___ cfe-com

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

2025-09-17 Thread Radovan Božić via cfe-commits
https://github.com/bozicrHT created https://github.com/llvm/llvm-project/pull/158626 Annotate printf/scanf and related builtins with the nonnull attribute on their format string parameters. This enables diagnostics when NULL is passed, matching GCC behavior. Updated existing Sema tests and add

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

2025-09-16 Thread Radovan Božić via cfe-commits
@@ -293,6 +293,34 @@ bool Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx, return isLike(ID, FormatIdx, HasVAListArg, "sS"); } +bool Builtin::Context::IsNonNull(unsigned ID, + llvm::SmallVectorImpl &Indxs) const { + + const ch

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

2025-09-16 Thread Radovan Božić via cfe-commits
@@ -17097,6 +17097,15 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { } } +SmallVector Indxs; +if (Context.BuiltinInfo.IsNonNull(BuiltinID, Indxs) && +!FD->hasAttr()) { + llvm::SmallVector ParamIndxs; + for (int I : Indxs) +