commit 3afef127c2996c8be4c24136f105ddebdbd0a437
parent 1341cf53a7115b1c89a2d2f836aef36524a6745e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 15 Aug 2015 12:33:04 +0200
Avoid emit prototype before of function definition
Diffstat:
7 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/cc1/decl.c b/cc1/decl.c
@@ -619,7 +619,7 @@ identifier(struct decl *dcl)
/* TODO: disallow initializators in functions */
/* TODO: check if typedef has initializer */
/* TODO: check if the variable is extern and has initializer */
- if (sym->token == IDEN)
+ if (sym->token == IDEN && sym->type->op != FTN)
emit(ODECL, sym);
return sym;
@@ -684,7 +684,7 @@ decl(void)
*/
if (sym->type->op == FTN) {
if (curctx != GLOBALCTX+1)
- goto remove_pars;
+ goto prototype;
switch (yytoken) {
case '{':
@@ -710,7 +710,8 @@ decl(void)
curfun = NULL;
return;
default:
- remove_pars:
+ prototype:
+ emit(ODECL, sym);
free(sym->u.pars);
popctx();
}
diff --git a/cc1/tests/test001.c b/cc1/tests/test001.c
@@ -5,7 +5,6 @@ output:
F3 P
X1 F3 printf
F1
-X2 F1 main
G2 F1 main {
-
X1 "68656C6C6F20776F726C640A aP pP cI
diff --git a/cc1/tests/test002.c b/cc1/tests/test002.c
@@ -4,7 +4,6 @@ description: Test forward references before definition of types
output:
G4 P x
F1
-X6 F1 main
G6 F1 main {
-
S2 S (
diff --git a/cc1/tests/test003.c b/cc1/tests/test003.c
@@ -3,17 +3,14 @@ name: TEST003
description: Select function to call inside ternary operator
output:
F1
-X1 F1 foo
G1 F1 foo {
-
yI #I2A
}
-X2 F1 bar
G2 F1 bar {
-
yI #I18
}
-X3 F1 main
G3 F1 main {
-
yI G1 cI
diff --git a/cc1/tests/test004.c b/cc1/tests/test004.c
@@ -3,7 +3,6 @@ name: TEST004
description: Test integer operations
output:
F1
-X1 F1 main
G1 F1 main {
-
A2 I x
diff --git a/cc1/tests/test005.c b/cc1/tests/test005.c
@@ -3,7 +3,6 @@ name: TEST005
description: Test unary integer operations
output:
F1
-X1 F1 main
G1 F1 main {
-
A2 I x
diff --git a/cc1/tests/test006.c b/cc1/tests/test006.c
@@ -2,12 +2,11 @@
name: TEST006
description: Basic test for if
output:
-test006.c:42: warning: conditional expression is constant
-test006.c:44: warning: conditional expression is constant
-test006.c:47: warning: conditional expression is constant
+test006.c:41: warning: conditional expression is constant
+test006.c:43: warning: conditional expression is constant
+test006.c:46: warning: conditional expression is constant
G1 M c
F1
-X2 F1 main
G2 F1 main {
-
j L2 #I0