Skip to content

Commit 19fdef4

Browse files
committed
Allow mixing old/new function prototypes
This fixes another external testsuite failure
1 parent 571868c commit 19fdef4

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

tccgen.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8517,7 +8517,7 @@ static int decl(int l)
85178517
{
85188518
int v, has_init, r, oldint;
85198519
CType type, btype;
8520-
Sym *sym;
8520+
Sym *sym, *s;
85218521
AttributeDef ad, adbase;
85228522
ElfSym *esym;
85238523

@@ -8589,6 +8589,21 @@ static int decl(int l)
85898589
if (sym->f.func_type == FUNC_OLD && l == VT_CONST) {
85908590
func_vt = type;
85918591
decl(VT_CMP);
8592+
8593+
/* Allow mixing old/new prototypes
8594+
* void func(float a);
8595+
* int main(void) { func(1.0); }
8596+
* void func(a) float a; { printf("%g\n", a); }
8597+
*/
8598+
s = sym_find(v);
8599+
if (type.ref->next && // skip old func(); definitions
8600+
s && s->type.ref &&
8601+
s->type.ref->f.func_type == FUNC_NEW) {
8602+
sym->f.func_type = FUNC_NEW;
8603+
if (!is_compatible_types(&s->type, &type))
8604+
tcc_error("incompatible redefinition of '%s'",
8605+
get_tok_str(v, NULL));
8606+
}
85928607
}
85938608

85948609
if ((type.t & (VT_EXTERN|VT_INLINE)) == (VT_EXTERN|VT_INLINE)) {
@@ -8646,6 +8661,9 @@ static int decl(int l)
86468661
while ((sym = sym->next) != NULL) {
86478662
if (!(sym->v & ~SYM_FIELD))
86488663
expect("identifier");
8664+
if (type.ref->f.func_type == FUNC_OLD &&
8665+
sym->type.t == VT_FLOAT)
8666+
sym->type.t = VT_DOUBLE;
86498667
if (sym->type.t == VT_VOID)
86508668
sym->type = int_type;
86518669
}
@@ -8693,9 +8711,6 @@ static int decl(int l)
86938711
if (sym->type.t != VT_VOID)
86948712
tcc_error("redefinition of parameter '%s'",
86958713
get_tok_str(v, NULL));
8696-
if (func_vt.ref->f.func_type == FUNC_OLD &&
8697-
type.t == VT_FLOAT)
8698-
type.t = VT_DOUBLE;
86998714
convert_parameter_type(&type);
87008715
sym->type = type;
87018716
} else if (type.t & VT_TYPEDEF) {

tests/tests2/133_old_func.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ float x;
66
return 2.0 * x;
77
}
88

9+
void func(float a);
10+
911
int
1012
main(void)
1113
{
1214
float fy();
1315

1416
printf("%g %g\n", fx(2.0), fy(10.0));
1517
printf("%g %g\n", fx(2.0f), fy(10.0f));
18+
func(1);
1619
}
1720

1821
float fy(x)
@@ -21,3 +24,8 @@ float x;
2124
return 3.0 * x;
2225
}
2326

27+
void func(a)
28+
float a;
29+
{
30+
printf("%g\n", a);
31+
}

tests/tests2/133_old_func.expect

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
4 30
22
4 30
3+
1

0 commit comments

Comments
 (0)