shithub: scc

Download patch

ref: 3afef127c2996c8be4c24136f105ddebdbd0a437
parent: 1341cf53a7115b1c89a2d2f836aef36524a6745e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Aug 15 08:33:04 EDT 2015

Avoid emit prototype before of function definition

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -619,7 +619,7 @@
 	/* 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 @@
 	 */
 	if (sym->type->op == FTN) {
 		if (curctx != GLOBALCTX+1)
-			goto remove_pars;
+			goto prototype;
 
 		switch (yytoken) {
 		case '{':
@@ -710,7 +710,8 @@
 			curfun = NULL;
 			return;
 		default:
-		remove_pars:
+		prototype:
+			emit(ODECL, sym);
 			free(sym->u.pars);
 			popctx();
 		}
--- a/cc1/tests/test001.c
+++ b/cc1/tests/test001.c
@@ -5,7 +5,6 @@
 F3	P
 X1	F3	printf
 F1
-X2	F1	main
 G2	F1	main	{
 -
 	X1	"68656C6C6F20776F726C640A	aP	pP	cI
--- a/cc1/tests/test002.c
+++ b/cc1/tests/test002.c
@@ -4,7 +4,6 @@
 output:
 G4	P	x
 F1
-X6	F1	main
 G6	F1	main	{
 -
 S2	S	(
--- a/cc1/tests/test003.c
+++ b/cc1/tests/test003.c
@@ -3,17 +3,14 @@
 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
--- a/cc1/tests/test004.c
+++ b/cc1/tests/test004.c
@@ -3,7 +3,6 @@
 description: Test integer operations
 output:
 F1
-X1	F1	main
 G1	F1	main	{
 -
 A2	I	x
--- a/cc1/tests/test005.c
+++ b/cc1/tests/test005.c
@@ -3,7 +3,6 @@
 description: Test unary integer operations
 output:
 F1
-X1	F1	main
 G1	F1	main	{
 -
 A2	I	x
--- 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