[clang] [analyzer] Fix security.VAList false positives with C23 va_start (PR #192024)
Björn Svensson via cfe-commits
cfe-commits at lists.llvm.org
Mon May 4 04:29:14 PDT 2026
================
@@ -0,0 +1,16 @@
+// Like the compiler, the static analyzer treats some functions differently if
+// they come from a system header -- for example, it is assumed that system
+// functions do not arbitrarily free() their parameters, and that some bugs
+// found in system headers cannot be fixed by the user and should be
+// suppressed.
+
+#pragma clang system_header
+
+typedef __builtin_va_list va_list;
+
+#define va_start(...) __builtin_c23_va_start(__VA_ARGS__)
+#define va_end(ap) __builtin_va_end(ap)
+#define va_arg(ap, type) __builtin_va_arg(ap, type)
+#define va_copy(dst, src) __builtin_va_copy(dst, src)
+
+int vprintf(const char *restrict format, va_list arg);
----------------
bjosv wrote:
Lets use `__restrict` then. But since `va_start` is defined as `__builtin_c23_va_start` that should only be used for `C23_LANG` anyway I guess?
This header is based on the existing `system-header-simulator-for-valist.h` that is used in non-C23 tests.
Optionally we could avoid adding this header and use the existing one, but I didn't find an existing pattern to use `__STDC_VERSION__` to differentiate defines in these headers, only that some headers have language specific naming using e.g. "-cxx.h".
https://github.com/llvm/llvm-project/pull/192024
More information about the cfe-commits
mailing list