From 2e5ef23826b14a195a0095045403ce2ea8877e64 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sun, 24 Mar 2024 02:16:52 -0700 Subject: decl: Implement GNU packed attribute Implements: https://todo.sr.ht/~mcf/cproc/72 --- test/struct-packed.c | 9 +++++++++ test/struct-packed.qbe | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 test/struct-packed.c create mode 100644 test/struct-packed.qbe (limited to 'test') 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 +} -- cgit v1.2.3