mirror of
https://github.com/frida/tinycc
synced 2025-01-12 14:49:18 +03:00
Fix parsing attributes for struct decls
Given this code: struct __attribute__((...)) Name {...}; TCC was eating "Name", hence generating an anonymous struct. It also didn't apply any packed attributes to the parsed members. Both fixed. The testcase also contains a case that isn't yet handled by TCC (under a BROKEN #define).
This commit is contained in:
parent
7e51546624
commit
2b618c1ab4
6
tccgen.c
6
tccgen.c
@ -3179,10 +3179,8 @@ static void struct_decl(CType *type, AttributeDef *ad, int u)
|
|||||||
|
|
||||||
a = tok; /* save decl type */
|
a = tok; /* save decl type */
|
||||||
next();
|
next();
|
||||||
if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2) {
|
if (tok == TOK_ATTRIBUTE1 || tok == TOK_ATTRIBUTE2)
|
||||||
parse_attribute(ad);
|
parse_attribute(ad);
|
||||||
next();
|
|
||||||
}
|
|
||||||
if (tok != '{') {
|
if (tok != '{') {
|
||||||
v = tok;
|
v = tok;
|
||||||
next();
|
next();
|
||||||
@ -3302,7 +3300,7 @@ static void struct_decl(CType *type, AttributeDef *ad, int u)
|
|||||||
if (ad1.a.aligned) {
|
if (ad1.a.aligned) {
|
||||||
if (align < ad1.a.aligned)
|
if (align < ad1.a.aligned)
|
||||||
align = ad1.a.aligned;
|
align = ad1.a.aligned;
|
||||||
} else if (ad1.a.packed) {
|
} else if (ad1.a.packed || ad->a.packed) {
|
||||||
align = 1;
|
align = 1;
|
||||||
} else if (*tcc_state->pack_stack_ptr) {
|
} else if (*tcc_state->pack_stack_ptr) {
|
||||||
if (align > *tcc_state->pack_stack_ptr)
|
if (align > *tcc_state->pack_stack_ptr)
|
||||||
|
@ -108,6 +108,7 @@ void cmp_comparison_test(void);
|
|||||||
void math_cmp_test(void);
|
void math_cmp_test(void);
|
||||||
void callsave_test(void);
|
void callsave_test(void);
|
||||||
void builtin_frame_address_test(void);
|
void builtin_frame_address_test(void);
|
||||||
|
void attrib_test(void);
|
||||||
|
|
||||||
int fib(int n);
|
int fib(int n);
|
||||||
void num(int n);
|
void num(int n);
|
||||||
@ -702,6 +703,7 @@ int main(int argc, char **argv)
|
|||||||
intdiv_test();
|
intdiv_test();
|
||||||
if (via_volatile (42) != 42)
|
if (via_volatile (42) != 42)
|
||||||
printf ("via_volatile broken\n");
|
printf ("via_volatile broken\n");
|
||||||
|
attrib_test();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2957,3 +2959,34 @@ char via_volatile (char i)
|
|||||||
vi = i;
|
vi = i;
|
||||||
return vi;
|
return vi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct __attribute__((__packed__)) Spacked {
|
||||||
|
char a;
|
||||||
|
short b;
|
||||||
|
int c;
|
||||||
|
};
|
||||||
|
struct Spacked spacked;
|
||||||
|
typedef struct __attribute__((__packed__)) {
|
||||||
|
char a;
|
||||||
|
short b;
|
||||||
|
int c;
|
||||||
|
} Spacked2;
|
||||||
|
Spacked2 spacked2;
|
||||||
|
#ifdef BROKEN
|
||||||
|
/* This doesn't work for now. Requires adjusting field offsets/sizes
|
||||||
|
after parsing the struct members. */
|
||||||
|
typedef struct Spacked3_s {
|
||||||
|
char a;
|
||||||
|
short b;
|
||||||
|
int c;
|
||||||
|
} __attribute__((__packed__)) Spacked3;
|
||||||
|
Spacked3 spacked3;
|
||||||
|
#endif
|
||||||
|
void attrib_test(void)
|
||||||
|
{
|
||||||
|
printf("attr: %d %d %d %d\n", sizeof(struct Spacked),
|
||||||
|
sizeof(spacked), sizeof(Spacked2), sizeof(spacked2));
|
||||||
|
#ifdef BROKEN
|
||||||
|
printf("attr: %d %d\n", sizeof(Spacked3), sizeof(spacked3));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user