Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CoTinker opened this issue Mar 23, 2024 · 1 comment · May be fixed by #86388
Open

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

CoTinker opened this issue Mar 23, 2024 · 1 comment · May be fixed by #86388

Comments

@CoTinker
Copy link
Contributor

CoTinker commented Mar 23, 2024

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 CoTinker linked a pull request Mar 23, 2024 that will close this issue
@EugeneZelenko EugeneZelenko changed the title [X86_32] Structure of size 0 int c++ get wrong result when emit vaarg [X86_32] Structure of size 0 in C++ get wrong result when emit vaarg Mar 23, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 23, 2024

@llvm/issue-subscribers-backend-x86

Author: Longsheng Mou (CoTinker)

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
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants