llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[X86_32] Structure of size 0 in C++ get wrong result when emit vaarg

Open CoTinker opened this issue 1 year ago • 1 comments

demo.c

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

struct S1644 {struct{int a[0];}b;} ;
struct S1644 s1644;
void check1644va (int z, ...) {
    struct S1644 arg;
    va_list ap;
    __builtin_va_start(ap, z);
    arg = __builtin_va_arg(ap, struct S1644);
    long double a = __builtin_va_arg(ap, long double);
    printf("%Lf\n", a);
    if (a != 2.0L)
       printf("Fail\n");
    __builtin_va_end(ap);
}
int main (void) {
    printf("%u\n", sizeof(s1644));
    check1644va (2, s1644, 2.0L);
}

clang:

0
0.000000
Fail

gcc:

0
2.000000

https://godbolt.org/z/G9enr4q5b

CoTinker avatar Mar 23 '24 09:03 CoTinker