packed attribute support
This commit is contained in:
parent
736b565766
commit
1e1d3ff687
2 changed files with 23 additions and 6 deletions
15
tcc.c
15
tcc.c
|
@ -215,6 +215,7 @@ typedef struct DLLReference {
|
|||
/* GNUC attribute definition */
|
||||
typedef struct AttributeDef {
|
||||
int aligned;
|
||||
int packed;
|
||||
Section *section;
|
||||
unsigned char func_call; /* FUNC_CDECL, FUNC_STDCALL, FUNC_FASTCALLx */
|
||||
} AttributeDef;
|
||||
|
@ -6175,8 +6176,10 @@ void inc(int post, int c)
|
|||
/* Parse GNUC __attribute__ extension. Currently, the following
|
||||
extensions are recognized:
|
||||
- aligned(n) : set data/function alignment.
|
||||
- packed : force data alignment to 1
|
||||
- section(x) : generate data/code in this section.
|
||||
- unused : currently ignored, but may be used someday.
|
||||
- regparm(n) : pass function parameters in registers (i386 only)
|
||||
*/
|
||||
static void parse_attribute(AttributeDef *ad)
|
||||
{
|
||||
|
@ -6214,6 +6217,10 @@ static void parse_attribute(AttributeDef *ad)
|
|||
}
|
||||
ad->aligned = n;
|
||||
break;
|
||||
case TOK_PACKED1:
|
||||
case TOK_PACKED2:
|
||||
ad->packed = 1;
|
||||
break;
|
||||
case TOK_UNUSED1:
|
||||
case TOK_UNUSED2:
|
||||
/* currently, no need to handle it because tcc does not
|
||||
|
@ -6364,8 +6371,12 @@ static void struct_decl(CType *type, int u)
|
|||
get_tok_str(v, NULL));
|
||||
}
|
||||
size = type_size(&type1, &align);
|
||||
if (ad.aligned) {
|
||||
if (align < ad.aligned)
|
||||
align = ad.aligned;
|
||||
} else if (ad.packed) {
|
||||
align = 1;
|
||||
}
|
||||
lbit_pos = 0;
|
||||
if (bit_size >= 0) {
|
||||
bt = type1.t & VT_BTYPE;
|
||||
|
@ -8480,8 +8491,12 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
|
|||
error("unknown type size");
|
||||
}
|
||||
/* take into account specified alignment if bigger */
|
||||
if (ad->aligned) {
|
||||
if (ad->aligned > align)
|
||||
align = ad->aligned;
|
||||
} else if (ad->packed) {
|
||||
align = 1;
|
||||
}
|
||||
if ((r & VT_VALMASK) == VT_LOCAL) {
|
||||
sec = NULL;
|
||||
if (do_bounds_check && (type->t & VT_ARRAY))
|
||||
|
|
2
tcctok.h
2
tcctok.h
|
@ -90,6 +90,8 @@
|
|||
DEF(TOK_SECTION2, "__section__")
|
||||
DEF(TOK_ALIGNED1, "aligned")
|
||||
DEF(TOK_ALIGNED2, "__aligned__")
|
||||
DEF(TOK_PACKED1, "packed")
|
||||
DEF(TOK_PACKED2, "__packed__")
|
||||
DEF(TOK_UNUSED1, "unused")
|
||||
DEF(TOK_UNUSED2, "__unused__")
|
||||
DEF(TOK_CDECL1, "cdecl")
|
||||
|
|
Loading…
Reference in a new issue