From a9e502cc3bae649fe4f9adffcd0715eb0a71d085 Mon Sep 17 00:00:00 2001 From: grischka Date: Sun, 9 Jul 2017 12:38:59 +0200 Subject: 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. --- tcc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'tcc.h') diff --git a/tcc.h b/tcc.h index 3e81e03..47c3c5f 100644 --- a/tcc.h +++ b/tcc.h @@ -450,6 +450,7 @@ typedef struct Sym { int sym_scope; /* scope level for locals */ int jnext; /* next jump label */ struct FuncAttr f; /* function attributes */ + int auxtype; /* bitfield access type */ }; }; long long enum_val; /* enum constant if IS_ENUM_VAL */ -- cgit v1.3.1