History

Fix function types

various cases of function type uses were broken by recent attribute refactoring, this fixes and adds testcases for them.

Michael Matz committed 9 years ago

Commit 04418c71 parent 2acb04f3 files · +42 −11Browse files

Unified · Split

3 files
  1. tccgen.c +19 −11
  2. tests/tests2/39_typedef.c +18 −0
  3. tests/tests2/82_attribs_position.c +5 −0
tccgen.c+19−11
@@ -3865,6 +3865,18 @@ do_decl: · 3864 unmodified lines
3865 }3865 }
3866}3866}
3867 3867
3868static void sym_to_attr(AttributeDef *ad, Sym *s)
3869{
3870 if (s->a.aligned && 0 == ad->a.aligned)
3871 ad->a.aligned = s->a.aligned;
3872 if (s->f.func_call && 0 == ad->f.func_call)
3873 ad->f.func_call = s->f.func_call;
3874 if (s->f.func_type && 0 == ad->f.func_type)
3875 ad->f.func_type = s->f.func_type;
3876 if (s->a.packed)
3877 ad->a.packed = 1;
3878}
3879
3868/* Add type qualifiers to a type. If the type is an array then the qualifiers3880/* Add type qualifiers to a type. If the type is an array then the qualifiers
3869 are added to the element type, copied because it could be a typedef. */3881 are added to the element type, copied because it could be a typedef. */
3870static void parse_btype_qualify(CType *type, int qualifiers)3882static void parse_btype_qualify(CType *type, int qualifiers)
@@ -4060,6 +4072,8 @@ static int parse_btype(CType *type, AttributeDef *ad) · 189 unmodified lines
4060 parse_expr_type(&type1);4072 parse_expr_type(&type1);
4061 /* remove all storage modifiers except typedef */4073 /* remove all storage modifiers except typedef */
4062 type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);4074 type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);
4075 if (type1.ref)
4076 sym_to_attr(ad, type1.ref);
4063 goto basic_type2;4077 goto basic_type2;
4064 default:4078 default:
4065 if (typespec_found)4079 if (typespec_found)
@@ -4075,12 +4089,7 @@ static int parse_btype(CType *type, AttributeDef *ad) · 9 unmodified lines
4075 parse_btype_qualify(type, t);4089 parse_btype_qualify(type, t);
4076 t = type->t;4090 t = type->t;
4077 /* get attributes from typedef */4091 /* get attributes from typedef */
4078 if (s->a.aligned && 0 == ad->a.aligned)4092 sym_to_attr(ad, s);
4079 ad->a.aligned = s->a.aligned;
4080 if (s->f.func_call && 0 == ad->f.func_call)
4081 ad->f.func_call = s->f.func_call;
4082 if (s->a.packed)
4083 ad->a.packed = 1;
4084 next();4093 next();
4085 typespec_found = 1;4094 typespec_found = 1;
4086 st = bt = -2;4095 st = bt = -2;
@@ -6978,7 +6987,7 @@ static void gen_inline_functions(TCCState *s) · 2891 unmodified lines
6978 6987
6979 ln = file->line_num;6988 ln = file->line_num;
6980 /* iterate while inline function are referenced */6989 /* iterate while inline function are referenced */
6981 for(;;) {6990 do {
6982 inline_generated = 0;6991 inline_generated = 0;
6983 for (i = 0; i < s->nb_inline_fns; ++i) {6992 for (i = 0; i < s->nb_inline_fns; ++i) {
6984 fn = s->inline_fns[i];6993 fn = s->inline_fns[i];
@@ -7000,9 +7009,7 @@ static void gen_inline_functions(TCCState *s) · 15 unmodified lines
7000 inline_generated = 1;7009 inline_generated = 1;
7001 }7010 }
7002 }7011 }
7003 if (!inline_generated)7012 } while (inline_generated);
7004 break;
7005 }
7006 file->line_num = ln;7013 file->line_num = ln;
7007}7014}
7008 7015
@@ -7229,12 +7236,13 @@ found: · 220 unmodified lines
7229 sym = sym_push(v, &type, 0, 0);7236 sym = sym_push(v, &type, 0, 0);
7230 }7237 }
7231 sym->a = ad.a;7238 sym->a = ad.a;
7239 sym->f = ad.f;
7232 } else {7240 } else {
7233 r = 0;7241 r = 0;
7234 if ((type.t & VT_BTYPE) == VT_FUNC) {7242 if ((type.t & VT_BTYPE) == VT_FUNC) {
7235 /* external function definition */7243 /* external function definition */
7236 /* specific case for func_call attribute */7244 /* specific case for func_call attribute */
7237 type.ref->a = ad.a;7245 type.ref->f = ad.f;
7238 } else if (!(type.t & VT_ARRAY)) {7246 } else if (!(type.t & VT_ARRAY)) {
7239 /* not lvalue if array */7247 /* not lvalue if array */
7240 r |= lvalue_type(type.t);7248 r |= lvalue_type(type.t);
tests/tests2/39_typedef.c+18−0
@@ -44,4 +44,22 @@ extern const int cb[1][2][3]; · 43 unmodified lines
44extern B b;44extern B b;
45extern int b[1][2][3];45extern int b[1][2][3];
46 46
47/* Funny but valid function declaration. */
48typedef int functype (int);
49extern functype func;
50int func(int i)
51{
52 return i + 1;
53}
54
55/* Even funnier function decl and definition using typeof. */
56int set_anon_super(void);
57int set_anon_super(void)
58{
59 return 42;
60}
61typedef int sas_type (void);
62extern typeof(set_anon_super) set_anon_super;
63extern sas_type set_anon_super;
64
47/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/65/* vim: set expandtab ts=4 sw=3 sts=3 tw=80 :*/
tests/tests2/82_attribs_position.c+5−0
@@ -11,4 +11,9 @@ typedef union __attribute__((packed)) Unaligned16b { · 10 unmodified lines
11 uint8_t b[2];11 uint8_t b[2];
12} Unaligned16b;12} Unaligned16b;
13 13
14extern void foo (void) __attribute__((stdcall));
15void __attribute__((stdcall)) foo (void)
16{
17}
18
14int main () { return 0; }19int main () { return 0; }

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