diff options
| author | Michael Matz <matz@suse.de> | 2016-10-17 20:27:23 +0200 |
|---|---|---|
| committer | Michael Matz <matz@suse.de> | 2016-12-15 17:49:56 +0100 |
| commit | f5ae4daa5f80d5230a93b600a0f40fe8c32b77d5 (patch) | |
| tree | 88f85119f02ffed150152099e259444ff3f9fec2 | |
| parent | 8859dc9e6d56e1d0f1d4eb4302a360899ec17c7d (diff) | |
| download | tinycc-f5ae4daa5f80d5230a93b600a0f40fe8c32b77d5.tar.gz tinycc-f5ae4daa5f80d5230a93b600a0f40fe8c32b77d5.tar.bz2 | |
struct-layout: Allow lowering of member alignment
when an alignment is explicitely given on the member itself,
or on its types attributes then respect it always. Was only
allowed to increase before, but GCC is allowing it.
| -rw-r--r-- | tccgen.c | 3 | ||||
| -rw-r--r-- | tests/tcctest.c | 16 |
2 files changed, 17 insertions, 2 deletions
@@ -3610,8 +3610,7 @@ static void struct_decl(CType *type, AttributeDef *ad, int u) alignoverride = 0; if (ad1.a.aligned) { int speca = 1 << (ad1.a.aligned - 1); - if (align < speca) - alignoverride = speca; + alignoverride = speca; } else if (ad1.a.packed || ad->a.packed) { alignoverride = 1; } else if (*tcc_state->pack_stack_ptr) { diff --git a/tests/tcctest.c b/tests/tcctest.c index 68f8db6..6c414f7 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1087,6 +1087,18 @@ struct Large { }; } __attribute__((aligned(2 * sizeof(long)))); +typedef unsigned long long __attribute__((aligned(4))) unaligned_u64; + +struct aligntest9 { + unsigned int buf_nr; + unaligned_u64 start_lba; +}; + +struct aligntest10 { + unsigned int buf_nr; + unsigned long long start_lba; +}; + void struct_test() { struct1 *s; @@ -1136,6 +1148,10 @@ void struct_test() sizeof(struct aligntest7), __alignof__(struct aligntest7)); printf("aligntest8 sizeof=%d alignof=%d\n", sizeof(struct aligntest8), __alignof__(struct aligntest8)); + printf("aligntest9 sizeof=%d alignof=%d\n", + sizeof(struct aligntest9), __alignof__(struct aligntest9)); + printf("aligntest10 sizeof=%d alignof=%d\n", + sizeof(struct aligntest10), __alignof__(struct aligntest10)); printf("altest5 sizeof=%d alignof=%d\n", sizeof(altest5), __alignof__(altest5)); printf("altest6 sizeof=%d alignof=%d\n", |
