History

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.

Michael Matz committed 10 years ago

Commit f5ae4da1 parent 8859dc92 files · +17 −2Browse files

Unified · Split

2 files
  1. tccgen.c +1 −2
  2. tests/tcctest.c +16 −0
tccgen.c+1−2
@@ -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) {
tests/tcctest.c+16−0
@@ -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
1090typedef unsigned long long __attribute__((aligned(4))) unaligned_u64;
1091
1092struct aligntest9 {
1093 unsigned int buf_nr;
1094 unaligned_u64 start_lba;
1095};
1096
1097struct aligntest10 {
1098 unsigned int buf_nr;
1099 unsigned long long start_lba;
1100};
1101
1090void struct_test()1102void 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",

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t