[clang] [clang] Catch missing format attributes (PR #70024)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 24 18:31:18 PDT 2023
================
@@ -435,6 +435,86 @@ bool Sema::ConstantFoldAttrArgs(const AttributeCommonInfo &CI,
return true;
}
+// Warn if parent function does not have builtin function format attribute.
+void Sema::DiagnoseMissingFormatAttributes(NamedDecl *FDecl,
+ SourceLocation Loc) {
+ if (!FDecl)
+ return;
+
+ auto *FD = dyn_cast_or_null<FunctionDecl>(FDecl);
+ if (!FD)
+ return;
+
+ unsigned BuiltinID = FD->getBuiltinID(/*ConsiderWrappers=*/true);
+
+ // Function is not builtin if it's builtin ID is 0.
+ if (!BuiltinID)
+ return;
----------------
aaronpuchert wrote:
What about calling a regular function that also has a `format` attribute? The GCC warning catches that as well.
https://github.com/llvm/llvm-project/pull/70024
More information about the cfe-commits
mailing list