diff options
| author | grischka <grischka> | 2017-07-09 12:38:59 +0200 |
|---|---|---|
| committer | grischka <grischka> | 2017-07-09 12:38:59 +0200 |
| commit | a9e502cc3bae649fe4f9adffcd0715eb0a71d085 (patch) | |
| tree | 6a61d98549fbf33ba25440f0d4db164fc695adce /tests | |
| parent | f87afa72e06842da1f1bb902e4a192195646134b (diff) | |
| download | tinycc-a9e502cc3bae649fe4f9adffcd0715eb0a71d085.tar.gz tinycc-a9e502cc3bae649fe4f9adffcd0715eb0a71d085.tar.bz2 | |
refactor bitfields
Use 2 level strategy to access packed bitfields cleanly:
1) Allow to override the original declaration type with
an auxilary "access type". This solves cases such as
struct {
...
unsigned f1:1;
};
by using VT_BYTE to access f1.
2) Allow byte-wise split accesses using two new functions
load/store_packed_bf. This solves any cases, also ones
such as
struct __attribute((packed)) _s {
unsigned x : 12;
unsigned char y : 7;
unsigned z : 28;
unsigned a: 3;
unsigned b: 3;
unsigned c: 3;
};
where for field 'z':
- VT_INT access from offset 2 would be unaligned
- VT_LLONG from offset 0 would go past the total
struct size (7)
and for field 'a' because it is in two bytes and
aligned access with VT_SHORT/INT is not possible.
Also, static bitfield initializers are stored byte-wise always.
Also, cleanup the struct_layout function a bit.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/tcctest.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/tcctest.c b/tests/tcctest.c index bc08968..10203ec 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1050,8 +1050,8 @@ int pad1; but __alignof__ returns the wrong result (4) because we can't store the alignment yet when specified on symbols directly (it's stored in the type so we'd need to make - a copy of it). -struct aligntest7 altest7[2] __attribute__((aligned(16)));*/ + a copy of it). -- FIXED */ +struct aligntest7 altest7[2] __attribute__((aligned(16))); struct aligntest8 { @@ -1161,8 +1161,8 @@ void struct_test() sizeof(altest5), __alignof__(altest5)); printf("altest6 sizeof=%d alignof=%d\n", sizeof(altest6), __alignof__(altest6)); - /*printf("altest7 sizeof=%d alignof=%d\n", - sizeof(altest7), __alignof__(altest7));*/ + printf("altest7 sizeof=%d alignof=%d\n", + sizeof(altest7), __alignof__(altest7)); /* empty structures (GCC extension) */ printf("sizeof(struct empty) = %d\n", sizeof(struct empty)); |
