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
36103610 alignoverride = 0;
36113611 if (ad1.a.aligned) {
36123612 int speca = 1 << (ad1.a.aligned - 1);
3613− if (align < speca)
3614− alignoverride = speca;
3613+ alignoverride = speca;
36153614 } else if (ad1.a.packed || ad->a.packed) {
36163615 alignoverride = 1;
36173616 } else if (*tcc_state->pack_stack_ptr) {
tests/tcctest.c+16−0
@@ -1087,6 +1087,18 @@ struct Large { · 1086 unmodified lines
10871087 };
10881088 } __attribute__((aligned(2 * sizeof(long))));
10891089
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+
10901102 void struct_test()
10911103 {
10921104 struct1 *s;
@@ -1136,6 +1148,10 @@ void struct_test() · 43 unmodified lines
11361148 sizeof(struct aligntest7), __alignof__(struct aligntest7));
11371149 printf("aligntest8 sizeof=%d alignof=%d\n",
11381150 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));
11391155 printf("altest5 sizeof=%d alignof=%d\n",
11401156 sizeof(altest5), __alignof__(altest5));
11411157 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