summaryrefslogtreecommitdiffstats
path: root/tests/017
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-05-24 07:25:24 -0700
committerKaz Kylheku <kaz@kylheku.com>2022-05-24 07:25:24 -0700
commit7b39d691a0fa1cffb2553237318c224d91bb9407 (patch)
treeaf831a63ba71960c3b61cc38c9b0394931313f53 /tests/017
parentfd37633953e63ac317b3dfd663f5cb0659d0aceb (diff)
downloadtxr-7b39d691a0fa1cffb2553237318c224d91bb9407.tar.gz
txr-7b39d691a0fa1cffb2553237318c224d91bb9407.tar.bz2
txr-7b39d691a0fa1cffb2553237318c224d91bb9407.zip
ffi: reproduce odd GNU C behavior for aligned bitfields.
We've already taken care of imitating the situation that GNU C allows __attribute__((aligned(n))) to weaken the alignment of a bitfield, contrary to it being documented that align only strengthens alignment. Even a value of n == 1 is meaningful in that it can cause the bitfield to start allocating from a new byte. This patch corrects a newly discovered nuance: when a bitfield is attributed with a weaker alignment than its underlying type (e.g. uint32_t field marked with 2 byte alignment), the original type's alignment is still in effect for calculating the alignment of the structure, and the padding. * ffi.c (struct txr_ffi_type): New member oalign, for keeping track of the type's original alignment, prior to adjustment. (make_ffi_type_struct): For a named bitfield, take the oalign value into account when determining the most strict member alignment. (ffi_type_compile): When marking a type as aligned, the we remember the original alignment in atft->oalign. * tests/017/bitfields.tl: New test case, struct s16. * txr.1: Documented.
Diffstat (limited to 'tests/017')
-rw-r--r--tests/017/bitfields.tl7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/017/bitfields.tl b/tests/017/bitfields.tl
index 5e8277f1..155a8b95 100644
--- a/tests/017/bitfields.tl
+++ b/tests/017/bitfields.tl
@@ -598,3 +598,10 @@
(b (bit 7 le-uint32)))))
(conv-test #S(s15 x 0 a #x1ff b #x7f) #b'00ffff')
+
+(typedef s16 (struct s16
+ (x uint8)
+ (a (align 2 (bit 9 le-uint32)))
+ (b (align 2 (bit 7 le-uint32)))))
+
+(conv-test #S(s16 x 0 a #x1ff b #x7f) #b'0000ff017f000000')