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.
Unified · Split
| @@ -3610,8 +3610,7 @@ static void struct_decl(CType *type, AttributeDef *ad, int u) · 3609 unmodified lines | |||
| 3610 | alignoverride = 0; | 3610 | alignoverride = 0; |
| 3611 | if (ad1.a.aligned) { | 3611 | if (ad1.a.aligned) { |
| 3612 | int speca = 1 << (ad1.a.aligned - 1); | 3612 | int speca = 1 << (ad1.a.aligned - 1); |
| 3613 | if (align < speca) | 3613 | alignoverride = speca; |
| 3614 | alignoverride = speca; | ||
| 3615 | } else if (ad1.a.packed || ad->a.packed) { | 3614 | } else if (ad1.a.packed || ad->a.packed) { |
| 3616 | alignoverride = 1; | 3615 | alignoverride = 1; |
| 3617 | } else if (*tcc_state->pack_stack_ptr) { | 3616 | } else if (*tcc_state->pack_stack_ptr) { |
| @@ -1087,6 +1087,18 @@ struct Large { · 1086 unmodified lines | |||
| 1087 | }; | 1087 | }; |
| 1088 | } __attribute__((aligned(2 * sizeof(long)))); | 1088 | } __attribute__((aligned(2 * sizeof(long)))); |
| 1089 | 1089 | ||
| 1090 | typedef unsigned long long __attribute__((aligned(4))) unaligned_u64; | ||
| 1091 | |||
| 1092 | struct aligntest9 { | ||
| 1093 | unsigned int buf_nr; | ||
| 1094 | unaligned_u64 start_lba; | ||
| 1095 | }; | ||
| 1096 | |||
| 1097 | struct aligntest10 { | ||
| 1098 | unsigned int buf_nr; | ||
| 1099 | unsigned long long start_lba; | ||
| 1100 | }; | ||
| 1101 | |||
| 1090 | void struct_test() | 1102 | void struct_test() |
| 1091 | { | 1103 | { |
| 1092 | struct1 *s; | 1104 | struct1 *s; |
| @@ -1136,6 +1148,10 @@ void struct_test() · 43 unmodified lines | |||
| 1136 | sizeof(struct aligntest7), __alignof__(struct aligntest7)); | 1148 | sizeof(struct aligntest7), __alignof__(struct aligntest7)); |
| 1137 | printf("aligntest8 sizeof=%d alignof=%d\n", | 1149 | printf("aligntest8 sizeof=%d alignof=%d\n", |
| 1138 | sizeof(struct aligntest8), __alignof__(struct aligntest8)); | 1150 | sizeof(struct aligntest8), __alignof__(struct aligntest8)); |
| 1151 | printf("aligntest9 sizeof=%d alignof=%d\n", | ||
| 1152 | sizeof(struct aligntest9), __alignof__(struct aligntest9)); | ||
| 1153 | printf("aligntest10 sizeof=%d alignof=%d\n", | ||
| 1154 | sizeof(struct aligntest10), __alignof__(struct aligntest10)); | ||
| 1139 | printf("altest5 sizeof=%d alignof=%d\n", | 1155 | printf("altest5 sizeof=%d alignof=%d\n", |
| 1140 | sizeof(altest5), __alignof__(altest5)); | 1156 | sizeof(altest5), __alignof__(altest5)); |
| 1141 | printf("altest6 sizeof=%d alignof=%d\n", | 1157 | printf("altest6 sizeof=%d alignof=%d\n", |