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
8517{8517{
8518 int v, has_init, r, oldint;8518 int v, has_init, r, oldint;
8519 CType type, btype;8519 CType type, btype;
8520 Sym *sym;8520 Sym *sym, *s;
8521 AttributeDef ad, adbase;8521 AttributeDef ad, adbase;
8522 ElfSym *esym;8522 ElfSym *esym;
8523 8523
@@ -8589,6 +8589,21 @@ static int decl(int l) · 65 unmodified lines
8589 if (sym->f.func_type == FUNC_OLD && l == VT_CONST) {8589 if (sym->f.func_type == FUNC_OLD && l == VT_CONST) {
8590 func_vt = type;8590 func_vt = type;
8591 decl(VT_CMP);8591 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 }
8592 }8607 }
8593 8608
8594 if ((type.t & (VT_EXTERN|VT_INLINE)) == (VT_EXTERN|VT_INLINE)) {8609 if ((type.t & (VT_EXTERN|VT_INLINE)) == (VT_EXTERN|VT_INLINE)) {
@@ -8646,6 +8661,9 @@ static int decl(int l) · 51 unmodified lines
8646 while ((sym = sym->next) != NULL) {8661 while ((sym = sym->next) != NULL) {
8647 if (!(sym->v & ~SYM_FIELD))8662 if (!(sym->v & ~SYM_FIELD))
8648 expect("identifier");8663 expect("identifier");
8664 if (type.ref->f.func_type == FUNC_OLD &&
8665 sym->type.t == VT_FLOAT)
8666 sym->type.t = VT_DOUBLE;
8649 if (sym->type.t == VT_VOID)8667 if (sym->type.t == VT_VOID)
8650 sym->type = int_type;8668 sym->type = int_type;
8651 }8669 }
@@ -8693,9 +8711,6 @@ static int decl(int l) · 41 unmodified lines
8693 if (sym->type.t != VT_VOID)8711 if (sym->type.t != VT_VOID)
8694 tcc_error("redefinition of parameter '%s'",8712 tcc_error("redefinition of parameter '%s'",
8695 get_tok_str(v, NULL));8713 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;
8699 convert_parameter_type(&type);8714 convert_parameter_type(&type);
8700 sym->type = type;8715 sym->type = type;
8701 } else if (type.t & VT_TYPEDEF) {8716 } else if (type.t & VT_TYPEDEF) {
tests/tests2/133_old_func.c+8−0
@@ -6,6 +6,8 @@ float x; · 5 unmodified lines
6 return 2.0 * x;6 return 2.0 * x;
7}7}
8 8
9void func(float a);
10
9int11int
10main(void)12main(void)
11{13{
@@ -13,6 +15,7 @@ main(void) · 1 unmodified line
13 15
14 printf("%g %g\n", fx(2.0), fy(10.0));16 printf("%g %g\n", fx(2.0), fy(10.0));
15 printf("%g %g\n", fx(2.0f), fy(10.0f));17 printf("%g %g\n", fx(2.0f), fy(10.0f));
18 func(1);
16}19}
17 20
18float fy(x)21float fy(x)
@@ -21,3 +24,8 @@ float x; · 2 unmodified lines
21 return 3.0 * x;24 return 3.0 * x;
22}25}
23 26
27void func(a)
28float a;
29{
30 printf("%g\n", a);
31}
tests/tests2/133_old_func.expect+1−0
@@ -1,2 +1,3 @@
14 3014 30
24 3024 30
31

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