diff options
author | Michael Forney <mforney@mforney.org> | 2024-03-24 02:16:52 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2024-03-24 02:41:37 -0700 |
commit | 2e5ef23826b14a195a0095045403ce2ea8877e64 (patch) | |
tree | 1d44af5fd14697d47c8f88139bc5103618f70682 /test | |
parent | 8e3ebaab5842d5fb8afcb977642277162de0611b (diff) |
decl: Implement GNU packed attribute
Implements: https://todo.sr.ht/~mcf/cproc/72
Diffstat (limited to 'test')
-rw-r--r-- | test/struct-packed.c | 9 | ||||
-rw-r--r-- | test/struct-packed.qbe | 17 |
2 files changed, 26 insertions, 0 deletions
diff --git a/test/struct-packed.c b/test/struct-packed.c new file mode 100644 index 0000000..d05bf91 --- /dev/null +++ b/test/struct-packed.c @@ -0,0 +1,9 @@ +struct [[gnu::packed]] { + char a; + long long b; + short c; +} s = {1, 2, 3}; + +int main(void) { + return s.a + s.b - s.c; +} diff --git a/test/struct-packed.qbe b/test/struct-packed.qbe new file mode 100644 index 0000000..ee79301 --- /dev/null +++ b/test/struct-packed.qbe @@ -0,0 +1,17 @@ +export data $s = align 1 { b 1, l 2, h 3, } +export +function w $main() { +@start.1 +@body.2 + %.1 =l add $s, 0 + %.2 =w loadsb %.1 + %.3 =l extsb %.2 + %.4 =l add $s, 1 + %.5 =l loadl %.4 + %.6 =l add %.3, %.5 + %.7 =l add $s, 9 + %.8 =w loadsh %.7 + %.9 =l extsh %.8 + %.10 =l sub %.6, %.9 + ret %.10 +} |