From e07ea69d611991a24d67076df906866c198252c0 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 4 Sep 2021 13:53:09 -0700 Subject: Use architecture-specific va_list type Previously, cproc effectively used used typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list[1]; However, this is not quite correct for x86_64 nor aarch64, though it was close enough for both to work in most cases. In actuality, for x86_64 we want typedef struct { /* 24 bytes, 8-byte aligned */ } __builtin_va_list[1]; and for aarch64 we want typedef struct { /* 32 bytes, 8-byte aligned */ } __builtin_va_list; The difference only appears when the size of va_list matters, or when va_list is passed as a parameter. However, the former is not often the case, and the aarch64 ABI replaces aggregate arguments with pointers to caller-allocated memory, which is quite similar to arrays decaying to pointers in C except that the struct is not copied. Additionally, riscv64 simply uses typedef void *__builtin_va_list; which again has a different size and calling convention. To fix this, make the __builtin_va_list type architecture-specific and use architecture-specific tests for varargs-related functionality. --- scope.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'scope.c') diff --git a/scope.c b/scope.c index 72025f5..c116670 100644 --- a/scope.c +++ b/scope.c @@ -25,13 +25,16 @@ scopeinit(void) {"__builtin_va_arg", {.kind = DECLBUILTIN, .builtin = BUILTINVAARG}}, {"__builtin_va_copy", {.kind = DECLBUILTIN, .builtin = BUILTINVACOPY}}, {"__builtin_va_end", {.kind = DECLBUILTIN, .builtin = BUILTINVAEND}}, - {"__builtin_va_list", {.kind = DECLTYPE, .type = &typevalist}}, {"__builtin_va_start", {.kind = DECLBUILTIN, .builtin = BUILTINVASTART}}, }; + static struct decl valist; struct builtin *b; for (b = builtins; b < builtins + LEN(builtins); ++b) scopeputdecl(&filescope, b->name, &b->decl); + valist.kind = DECLTYPE; + valist.type = targ->typevalist; + scopeputdecl(&filescope, "__builtin_va_list", &valist); } struct scope * -- cgit v1.2.3