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
38653865 }
38663866 }
38673867
3868+static 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+
38683880 /* Add type qualifiers to a type. If the type is an array then the qualifiers
38693881 are added to the element type, copied because it could be a typedef. */
38703882 static void parse_btype_qualify(CType *type, int qualifiers)
@@ -4060,6 +4072,8 @@ static int parse_btype(CType *type, AttributeDef *ad) · 189 unmodified lines
40604072 parse_expr_type(&type1);
40614073 /* remove all storage modifiers except typedef */
40624074 type1.t &= ~(VT_STORAGE&~VT_TYPEDEF);
4075+ if (type1.ref)
4076+ sym_to_attr(ad, type1.ref);
40634077 goto basic_type2;
40644078 default:
40654079 if (typespec_found)
@@ -4075,12 +4089,7 @@ static int parse_btype(CType *type, AttributeDef *ad) · 9 unmodified lines
40754089 parse_btype_qualify(type, t);
40764090 t = type->t;
40774091 /* get attributes from typedef */
4078− if (s->a.aligned && 0 == ad->a.aligned)
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;
4092+ sym_to_attr(ad, s);
40844093 next();
40854094 typespec_found = 1;
40864095 st = bt = -2;
@@ -6978,7 +6987,7 @@ static void gen_inline_functions(TCCState *s) · 2891 unmodified lines
69786987
69796988 ln = file->line_num;
69806989 /* iterate while inline function are referenced */
6981− for(;;) {
6990+ do {
69826991 inline_generated = 0;
69836992 for (i = 0; i < s->nb_inline_fns; ++i) {
69846993 fn = s->inline_fns[i];
@@ -7000,9 +7009,7 @@ static void gen_inline_functions(TCCState *s) · 15 unmodified lines
70007009 inline_generated = 1;
70017010 }
70027011 }
7003− if (!inline_generated)
7004− break;
7005− }
7012+ } while (inline_generated);
70067013 file->line_num = ln;
70077014 }
70087015
@@ -7229,12 +7236,13 @@ found: · 220 unmodified lines
72297236 sym = sym_push(v, &type, 0, 0);
72307237 }
72317238 sym->a = ad.a;
7239+ sym->f = ad.f;
72327240 } else {
72337241 r = 0;
72347242 if ((type.t & VT_BTYPE) == VT_FUNC) {
72357243 /* external function definition */
72367244 /* specific case for func_call attribute */
7237− type.ref->a = ad.a;
7245+ type.ref->f = ad.f;
72387246 } else if (!(type.t & VT_ARRAY)) {
72397247 /* not lvalue if array */
72407248 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
4444 extern B b;
4545 extern int b[1][2][3];
4646
47+/* Funny but valid function declaration. */
48+typedef int functype (int);
49+extern functype func;
50+int func(int i)
51+{
52+ return i + 1;
53+}
54+
55+/* Even funnier function decl and definition using typeof. */
56+int set_anon_super(void);
57+int set_anon_super(void)
58+{
59+ return 42;
60+}
61+typedef int sas_type (void);
62+extern typeof(set_anon_super) set_anon_super;
63+extern sas_type set_anon_super;
64+
4765 /* 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
1111 uint8_t b[2];
1212 } Unaligned16b;
1313
14+extern void foo (void) __attribute__((stdcall));
15+void __attribute__((stdcall)) foo (void)
16+{
17+}
18+
1419 int 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