From 487079af3d6f39b379f52f7e0ea6edec63587e5b Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 27 Apr 2024 14:29:02 -0700 Subject: qbe: Add extra size for strict alignment with QBE instruction With upcoming VLA support, the size might not be constant. --- qbe.c | 7 +++---- test/alignas-local-32.c | 4 ---- test/alignas-local-32.qbe | 11 ----------- test/alignas-local-strict.c | 4 ++++ test/alignas-local-strict.qbe | 12 ++++++++++++ 5 files changed, 19 insertions(+), 19 deletions(-) delete mode 100644 test/alignas-local-32.c delete mode 100644 test/alignas-local-32.qbe create mode 100644 test/alignas-local-strict.c create mode 100644 test/alignas-local-strict.qbe diff --git a/qbe.c b/qbe.c index adbc6f7..c3424c5 100644 --- a/qbe.c +++ b/qbe.c @@ -268,24 +268,23 @@ funcalloc(struct func *f, struct decl *d) enum instkind op; struct block *end; struct value *v; - unsigned long long size; int align; assert(!d->type->incomplete); assert(d->type->size > 0); end = f->end; f->end = f->start; - size = d->type->size; + v = mkintconst(d->type->size); align = d->u.obj.align; switch (align) { case 1: case 2: case 4: op = IALLOC4; break; case 8: op = IALLOC8; break; - default: size += align - 16; /* fallthrough */ + default: v = funcinst(f, IADD, ptrclass, v, mkintconst(align - 16)); /* fallthrough */ case 16: op = IALLOC16; break; } - v = funcinst(f, op, ptrclass, mkintconst(size), NULL); + v = funcinst(f, op, ptrclass, v, NULL); if (align > 16) { /* TODO: implement alloc32 in QBE and use that instead */ v = funcinst(f, IADD, ptrclass, v, mkintconst(align - 16)); diff --git a/test/alignas-local-32.c b/test/alignas-local-32.c deleted file mode 100644 index e390713..0000000 --- a/test/alignas-local-32.c +++ /dev/null @@ -1,4 +0,0 @@ -int main(void) { - alignas(32) char x; - return (unsigned long)&x % 32; -} diff --git a/test/alignas-local-32.qbe b/test/alignas-local-32.qbe deleted file mode 100644 index 53bfab3..0000000 --- a/test/alignas-local-32.qbe +++ /dev/null @@ -1,11 +0,0 @@ -export -function w $main() { -@start.1 - %.1 =l alloc16 17 - %.2 =l add %.1, 16 - %.3 =l and %.2, 18446744073709551584 -@body.2 - %.4 =l extsw 32 - %.5 =l urem %.3, %.4 - ret %.5 -} diff --git a/test/alignas-local-strict.c b/test/alignas-local-strict.c new file mode 100644 index 0000000..e390713 --- /dev/null +++ b/test/alignas-local-strict.c @@ -0,0 +1,4 @@ +int main(void) { + alignas(32) char x; + return (unsigned long)&x % 32; +} diff --git a/test/alignas-local-strict.qbe b/test/alignas-local-strict.qbe new file mode 100644 index 0000000..8c725ff --- /dev/null +++ b/test/alignas-local-strict.qbe @@ -0,0 +1,12 @@ +export +function w $main() { +@start.1 + %.1 =l add 1, 16 + %.2 =l alloc16 %.1 + %.3 =l add %.2, 16 + %.4 =l and %.3, 18446744073709551584 +@body.2 + %.5 =l extsw 32 + %.6 =l urem %.4, %.5 + ret %.6 +} -- cgit v1.2.3