[clang] [C23] Add __builtin_c23_va_start (PR #131166)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 13 11:49:30 PDT 2025
================
@@ -4844,15 +4845,27 @@ static bool checkVAStartIsInVariadicFunction(Sema &S, Expr *Fn,
bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall) {
Expr *Fn = TheCall->getCallee();
-
if (checkVAStartABI(*this, BuiltinID, Fn))
return true;
- // In C23 mode, va_start only needs one argument. However, the builtin still
- // requires two arguments (which matches the behavior of the GCC builtin),
- // <stdarg.h> passes `0` as the second argument in C23 mode.
- if (checkArgCount(TheCall, 2))
- return true;
+ if (BuiltinID == Builtin::BI__builtin_c23_va_start) {
+ // This builtin requires one argument (the va_list), allows two arguments,
+ // but diagnoses more than two arguments. e.g.,
+ // __builtin_c23_va_start(); // error
+ // __builtin_c23_va_start(list); // ok
+ // __builtin_c23_va_start(list, param); // ok
+ // __builtin_c23_va_start(list, anything, anything); // error
+ // This differs from the GCC behavior in that they accept the last case
+ // with a warning, but it doesn't seem like a useful behavior to allow.
+ if (checkArgCountRange(TheCall, 1, 2))
+ return true;
+ } else {
+ // In C23 mode, va_start only needs one argument. However, the builtin still
+ // requires two arguments (which matches the behavior of the GCC builtin),
+ // <stdarg.h> passes `0` as the second argument in C23 mode.
----------------
Sirraide wrote:
Makes sense
https://github.com/llvm/llvm-project/pull/131166
More information about the cfe-commits
mailing list