aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2021-10-24 22:47:44 -0700
committerMichael Forney <mforney@mforney.org>2024-03-24 02:41:18 -0700
commit731e7a2f3bf18baa4d4ce966006637ee13c5651a (patch)
tree8bc4457c7c663b544ccc0386dbabcccd7259a45a /test
parent7585cbb758b7bc2169cba42b7665d46f0c57db93 (diff)
Add support for C23 attribute syntax
Currently, all attributes are ignored. References: https://todo.sr.ht/~mcf/cproc/68
Diffstat (limited to 'test')
-rw-r--r--test/attribute-syntax.c79
-rw-r--r--test/attribute-syntax.qbe22
2 files changed, 101 insertions, 0 deletions
diff --git a/test/attribute-syntax.c b/test/attribute-syntax.c
new file mode 100644
index 0000000..1be4260
--- /dev/null
+++ b/test/attribute-syntax.c
@@ -0,0 +1,79 @@
+/* applies to a and b */
+[[dummy]] int a, b;
+
+/* applies only to d */
+int c, d [[dummy]];
+
+/* applies to type int in this instance */
+int [[dummy]] x;
+
+/* applies to array type */
+int array[8] [[dummy]];
+
+/* applies to function type */
+int function(void) [[dummy]];
+
+/* applies to pointer type */
+int *[[dummy]]const pointer;
+
+/* standalone attribute is implementation-defined */
+[[dummy]];
+
+/* applies to type `struct s`, here and elsewhere */
+struct [[dummy]] s {
+ /* applies to i */
+ [[dummy]] int i;
+
+ /* applies to type float in this instance */
+ float [[dummy]] f;
+};
+
+/* applies to type `union u`, here and elsewhere */
+union [[dummy]] u {
+ /* applies to i */
+ [[dummy]] int i;
+
+ /* applies to type float in this instance */
+ float [[dummy]] f;
+};
+
+/* applies to type `enum e`, here and elsewhere */
+enum [[dummy]] e {
+ /* applies to E1 */
+ E1 [[dummy]],
+
+ /* applies to E2 */
+ E2 [[dummy]] = 123,
+};
+
+/* applies to function */
+[[dummy]] void f([[dummy]] int p1 /* applies to p1 */, int [[dummy]] p2 /* applies to type int */) {
+ /* applies to type int */
+ sizeof(int [[dummy]]);
+
+ /* applies to array type */
+ sizeof(int[4] [[dummy]]);
+
+ /* applies to function type */
+ sizeof(int (*)(float) [[dummy]]);
+
+ /* applies to pointer type */
+ sizeof(int *[[dummy]]);
+
+ /* applies to statement */
+ [[dummy]]
+ if (0)
+ ;
+
+ /* applies to label */
+ [[dummy]]
+ L1: 0;
+
+ /* applies to statement */
+ L2: [[dummy]]0;
+}
+
+[[dummy(attribute with parameters [123 456 ({+ -} if else)])]];
+[[dummy1,dummy2,,dummy3]];
+[[]];
+[[dummy1]] [[dummy2]];
diff --git a/test/attribute-syntax.qbe b/test/attribute-syntax.qbe
new file mode 100644
index 0000000..ad8f4cc
--- /dev/null
+++ b/test/attribute-syntax.qbe
@@ -0,0 +1,22 @@
+export
+function $f(w %.1, w %.3) {
+@start.1
+ %.2 =l alloc4 4
+ storew %.1, %.2
+ %.4 =l alloc4 4
+ storew %.3, %.4
+@body.2
+ jnz 0, @if_true.3, @if_false.4
+@if_true.3
+@if_false.4
+@L1.5
+@L2.6
+ ret
+}
+export data $a = align 4 { z 4 }
+export data $b = align 4 { z 4 }
+export data $c = align 4 { z 4 }
+export data $d = align 4 { z 4 }
+export data $x = align 4 { z 4 }
+export data $array = align 4 { z 32 }
+export data $pointer = align 8 { z 8 }