From 28961f9197c8c5356f29fffac0cc322788441759 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Wed, 27 Oct 2021 19:31:24 -0700 Subject: decl: Use strictest alignment when multiple specifiers are present This is specified by the last sentence in C11 6.7.5p6. --- decl.c | 14 +++++--------- test/alignas-multiple.c | 1 + test/alignas-multiple.qbe | 1 + 3 files changed, 7 insertions(+), 9 deletions(-) create mode 100644 test/alignas-multiple.c create mode 100644 test/alignas-multiple.qbe diff --git a/decl.c b/decl.c index d31196f..68fc2d0 100644 --- a/decl.c +++ b/decl.c @@ -375,15 +375,11 @@ declspecs(struct scope *s, enum storageclass *sc, enum funcspec *fs, int *align) next(); expect(TLPAREN, "after '_Alignas'"); other = typename(s, NULL); - if (other) { - *align = other->align; - } else { - i = intconstexpr(s, false); - if (i & (i - 1)) - error(&tok.loc, "invalid alignment: %d", i); - if (i) - *align = (int)i; - } + i = other ? other->align : intconstexpr(s, false); + if (i & (i - 1)) + error(&tok.loc, "invalid alignment: %d", i); + if (i > *align) + *align = i; expect(TRPAREN, "to close '_Alignas' specifier"); break; diff --git a/test/alignas-multiple.c b/test/alignas-multiple.c new file mode 100644 index 0000000..7fc2199 --- /dev/null +++ b/test/alignas-multiple.c @@ -0,0 +1 @@ +_Alignas(8) _Alignas(4) char x; diff --git a/test/alignas-multiple.qbe b/test/alignas-multiple.qbe new file mode 100644 index 0000000..fd85074 --- /dev/null +++ b/test/alignas-multiple.qbe @@ -0,0 +1 @@ +export data $x = align 8 { z 1 } -- cgit v1.2.3