[llvm] [Verifier] Reject va_start in non-variadic function (PR #88809)
Aaron Ballman via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 17 04:53:34 PDT 2024
AaronBallman 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.
Ugh, sorry for the confusion with my example, that was... egregiously confusing. :-D I meant:
```
/* Type your code here, or load an example. */
#include <stdarg.h>
void func(...) {
va_list list;
va_start(list);
...
va_end(list);
}
void foo() {
func();
}
```
and the only goal for the request was to make sure that the IR verifier still considers `func` to be variadic despite the lack of any parameters other than `...` (which I presume it will handle just fine). If you don't think that's a reasonable test to add, I also don't insist either. Sorry for the confusion!
https://github.com/llvm/llvm-project/pull/88809
More information about the llvm-commits
mailing list