aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-04-11 17:35:43 -0700
committerMichael Forney <mforney@mforney.org>2021-04-11 17:37:33 -0700
commitebdae640721cd7be00db01b6e5d0793b46926f3b (patch)
treef0bc0c7479692268fae90ccff0c4d797a54ca31e
parent0c2e1bf9b32bd429bd01f0baec6893afd372d354 (diff)
decl: Allow _Alignas(0)
C11 6.7.5p6 says "An alignment specification of zero has no effect".
-rw-r--r--decl.c5
-rw-r--r--test/alignas-0.c3
-rw-r--r--test/alignas-0.qbe3
-rw-r--r--test/alignas-type.c1
-rw-r--r--test/alignas-type.qbe1
-rw-r--r--test/alignas.c2
-rw-r--r--test/alignas.qbe2
7 files changed, 13 insertions, 4 deletions
diff --git a/decl.c b/decl.c
index 94e4b15..0c3b037 100644
--- a/decl.c
+++ b/decl.c
@@ -379,9 +379,10 @@ declspecs(struct scope *s, enum storageclass *sc, enum funcspec *fs, int *align)
*align = other->align;
} else {
i = intconstexpr(s, false);
- if (!i || i & (i - 1) || i > 16)
+ if (i & (i - 1) || i > 16)
error(&tok.loc, "invalid alignment: %d", i);
- *align = (int)i;
+ if (i)
+ *align = (int)i;
}
expect(TRPAREN, "to close '_Alignas' specifier");
break;
diff --git a/test/alignas-0.c b/test/alignas-0.c
new file mode 100644
index 0000000..402e7ee
--- /dev/null
+++ b/test/alignas-0.c
@@ -0,0 +1,3 @@
+_Alignas(0) int x;
+_Alignas(8) _Alignas(0) int y;
+_Alignas(0) _Alignas(16) int z;
diff --git a/test/alignas-0.qbe b/test/alignas-0.qbe
new file mode 100644
index 0000000..849fb58
--- /dev/null
+++ b/test/alignas-0.qbe
@@ -0,0 +1,3 @@
+export data $x = align 4 { z 4 }
+export data $y = align 8 { z 4 }
+export data $z = align 16 { z 4 }
diff --git a/test/alignas-type.c b/test/alignas-type.c
new file mode 100644
index 0000000..394045d
--- /dev/null
+++ b/test/alignas-type.c
@@ -0,0 +1 @@
+_Alignas(int) char x[4];
diff --git a/test/alignas-type.qbe b/test/alignas-type.qbe
new file mode 100644
index 0000000..7cf0e40
--- /dev/null
+++ b/test/alignas-type.qbe
@@ -0,0 +1 @@
+export data $x = align 4 { z 4 }
diff --git a/test/alignas.c b/test/alignas.c
index 394045d..b714d37 100644
--- a/test/alignas.c
+++ b/test/alignas.c
@@ -1 +1 @@
-_Alignas(int) char x[4];
+_Alignas(8) int x;
diff --git a/test/alignas.qbe b/test/alignas.qbe
index 7cf0e40..6dd5505 100644
--- a/test/alignas.qbe
+++ b/test/alignas.qbe
@@ -1 +1 @@
-export data $x = align 4 { z 4 }
+export data $x = align 8 { z 4 }