History

Allow mixing old/new function prototypes

This fixes another external testsuite failure

herman ten brugge committed 1 year ago

Commit 19fdef41 parent 571868c3 files · +28 −4Browse files

Unified · Split

3 files
  1. tccgen.c +19 −4
  2. tests/tests2/133_old_func.c +8 −0
  3. tests/tests2/133_old_func.expect +1 −0
tccgen.c+19−4
@@ -8517,7 +8517,7 @@ static int decl(int l) · 8516 unmodified lines
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) · 65 unmodified lines
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) · 51 unmodified lines
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) · 41 unmodified lines
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+8−0
@@ -6,6 +6,8 @@ float x; · 5 unmodified lines
66 return 2.0 * x;
77 }
88
9+void func(float a);
10+
911 int
1012 main(void)
1113 {
@@ -13,6 +15,7 @@ main(void) · 1 unmodified line
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; · 2 unmodified lines
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+1−0
@@ -1,2 +1,3 @@
11 4 30
22 4 30
3+1

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