Issue 77036
Summary [x86_64][clang] Empty structure argument are ignored in function variable arguments.
Labels clang
Assignees
Reporter CoTinker
    demo
```
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

extern void *memset (void *__s, int __c, size_t __n);
struct S14 { 
    union{}a; 
};

struct S14 s14;

void check14va (int z, ...) { 
	struct S14 arg, *p; 
	va_list ap; 
    __builtin_va_start(ap, z); 
    arg = __builtin_va_arg(ap, struct S14); 
    double va = __builtin_va_arg(ap, long double);
    printf("%f\n", va);
    if (va != 2.0L) 
        printf("Fail\n"); 
    __builtin_va_end(ap); 
}

int main() {
    memset (&s14, '\0', sizeof(s14));
 check14va(2, s14, 2.0L);
    return 0;
}
```
clang output:
```
0.000000
Fail
```
gcc output:
```
2.000000
```
https://godbolt.org/z/6ErKWPq15

llvm IR
```
define dso_local noundef i32 @main() {
entry:
  %retval = alloca i32, align 4
  %agg.tmp = alloca %struct.S14, align 1
  store i32 0, ptr %retval, align 4
  call void @llvm.memset.p0.i64(ptr align 1 @s14, i8 0, i64 1, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %agg.tmp, ptr align 1 @s14, i64 1, i1 false)
  call void (i32, ...) @check14va(int, ...)(i32 noundef 2, x86_fp80 noundef 0xK40008000000000000000)
  ret i32 0
}
```
I find that clang ignore the empty structure argument `s14`. As a result, the subsequent running result does not meet the expectation.

https://github.com/llvm/llvm-project/blob/597086c60959dd5b3c032552e8b42dd1d053f233/clang/lib/CodeGen/Targets/X86.cpp#L2698-L2701

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to