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. `
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
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
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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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
@@ -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)
+
11 matches
Mail list logo