From 731e7a2f3bf18baa4d4ce966006637ee13c5651a Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 24 Oct 2021 22:47:44 -0700 Subject: Add support for C23 attribute syntax Currently, all attributes are ignored. References: https://todo.sr.ht/~mcf/cproc/68 --- test/attribute-syntax.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++ test/attribute-syntax.qbe | 22 +++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 test/attribute-syntax.c create mode 100644 test/attribute-syntax.qbe (limited to 'test') 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 } -- cgit v1.2.3