[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


================
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wmissing-format-attribute %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c99 -Wmissing-format-attribute %s
+
+#include <stdarg.h>
+#include <stdio.h>
+
+va_list args;
+
+__attribute__((__format__ (__scanf__, 1, 4)))
+void foo(char *out, const size_t len, const char *format, ... /* args */)
+{
+    vsnprintf(out, len, format, args); // expected-warning {{Function 'foo' might be candidate for 'printf' format attribute}}
----------------
aaronpuchert wrote:

Add a test where we're calling the function with non-argument format string and variadic arguments. Then the warning should not be emitted. Not sure about mixing argument format string and non-argument variadic arguments and the other way around, but these should probably not warn either, since we can't propagate the attribute.

Also where we're taking a `va_list` as argument and forwarding that. This should also warn.

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


More information about the cfe-commits mailing list