scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit eeb27df427be42257158bdc615de24509c033e9f
parent 6cc9c2edc5e009d3b000e04c84c713a53d2be470
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  1 Nov 2022 22:52:50 +0100

cc1/cc2: Implement va_copy()

va_list can be implemented using a pointer or an array of 1 element
and in the second case is needed to take the content of the pointer
because copying just the pointer will not work in that case.

Diffstat:
Msrc/cmd/cc/cc1/builtin.c | 9+++++++--
Msrc/cmd/cc/cc2/target/amd64-sysv/types.c | 1+
Msrc/cmd/cc/cc2/target/arm64-sysv/types.c | 1+
Msrc/cmd/cc/cc2/target/i386-sysv/types.c | 5++---
Msrc/cmd/cc/cc2/target/qbe/cgen.c | 3---
Msrc/cmd/cc/cc2/target/z80-scc/types.c | 5++---
6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/src/cmd/cc/cc1/builtin.c b/src/cmd/cc/cc1/builtin.c @@ -46,8 +46,13 @@ builtin_va_copy(Symbol *sym) return constnode(zero); } - np = node(OBUILTIN, voidtype, dst, src); - np->sym = sym; + if (dst->type != va_type) + dst = node(OPTR, dst->type->type, dst, NULL); + if (src->type != va_type) + src = node(OPTR, src->type->type, src, NULL); + np = node(OASSIGN, dst->type, dst, src); + np = node(OCAST, voidtype, np, NULL); + return np; } diff --git a/src/cmd/cc/cc2/target/amd64-sysv/types.c b/src/cmd/cc/cc2/target/amd64-sysv/types.c @@ -87,6 +87,7 @@ Type voidtype = { }; Type arg_type = { + .flags = ARRF, .size = 24, .align = 8 }; diff --git a/src/cmd/cc/cc2/target/arm64-sysv/types.c b/src/cmd/cc/cc2/target/arm64-sysv/types.c @@ -87,6 +87,7 @@ Type voidtype = { }; Type arg_type = { + .flags = ARRF, .size = 24, .align = 8 }; diff --git a/src/cmd/cc/cc2/target/i386-sysv/types.c b/src/cmd/cc/cc2/target/i386-sysv/types.c @@ -86,8 +86,7 @@ Type voidtype = { .align = 0 }; -/* this type is not used in this architecture */ Type arg_type = { - .size = 0, - .align = 0 + .size = 4, + .align = 4 }; diff --git a/src/cmd/cc/cc2/target/qbe/cgen.c b/src/cmd/cc/cc2/target/qbe/cgen.c @@ -705,7 +705,6 @@ rhs(Node *np) case BVA_START: l = rhs(l); code(ASVSTAR, NULL, l, NULL); - return NULL; case BVA_END: return NULL; case BVA_ARG: @@ -713,8 +712,6 @@ rhs(Node *np) tmp = tmpnode(tp); code(ASVARG, tmp, l, NULL); return tmp; - case BVA_COPY: - /* TODO */ default: abort(); } diff --git a/src/cmd/cc/cc2/target/z80-scc/types.c b/src/cmd/cc/cc2/target/z80-scc/types.c @@ -86,8 +86,7 @@ Type voidtype = { .align = 0 }; -/* this types is not going to be used in this arch */ Type arg_type = { - .size = 0, - .align = 0 + .size = 2, + .align = 1 };