[llvm] [Verifier] Reject va_start in non-variadic function (PR #88809)
Jon Chesterfield via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 12:26:04 PDT 2024
JonChesterfield wrote:
@AaronBallman I don't understand what you're asking here. C23 didn't change anything applicable to this as far as I'm aware. If it did, the problem would be in clang sema, not in the IR verifier.
Prepending the stdarg include and specifying c23 https://godbolt.org/z/Eqr3vTa9K gets the expected errors:
```
<source>:8:3: error: 'va_start' used in function with fixed args
8 | va_start(list);
| ^
/opt/compiler-explorer/clang-assertions-trunk-20240416/lib/clang/19/include/__stdarg_va_arg.h:14:27: note: expanded from macro 'va_start'
14 | #define va_start(ap, ...) __builtin_va_start(ap, 0)
| ^
<source>:9:3: error: expected expression
9 | ...
| ^
2 errors generated.
Compiler returned: 1
```
Did you want `void foo(...)`, i.e. have no fixed arguments? That creates valid IR with the ... expression removed,
```
define dso_local void @foo(...) #0 {
entry:
%list = alloca [1 x %struct.__va_list_tag], align 16
%arraydecay = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %list, i64 0, i64 0
call void @llvm.va_start.p0(ptr %arraydecay)
%arraydecay1 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %list, i64 0, i64 0
call void @llvm.va_end.p0(ptr %arraydecay1)
ret void
}
```
which is fine, it's a va_start in a variadic function.
https://github.com/llvm/llvm-project/pull/88809
More information about the llvm-commits
mailing list