shithub: scc

Download patch

ref: f49e6a2567d28ca03446691fe3f249940f9d734c
parent: 8fa4d78c9bdcea6207df841df6da28fd2b8170a9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Feb 15 03:58:45 EST 2017

[cc1] Fix prototype declaration

It is not needed to free the parameters of a function anymore in
decl(), because this work is already done in popctx(), although
it was harmless, since popcxt() was setting the pointer to NULL.
The main problem was this piece of code:

	expect(';');
	curfun = ocurfun;

Expect(';') was called before setting curfun properly, and it
means that the old value of curfun was used in expect,
which caused that several things were freed twice.

--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -873,10 +873,8 @@
 		for (p = sym->u.pars;  p && *p; ++p)
 			(*p)->flags |= SUSED;
 		popctx();
-		expect(';');
-		free(sym->u.pars);
-		sym->u.pars = NULL;
 		curfun = ocurfun;
+		expect(';');
 		return;
 	}
 	if (sym->type->prop & TK_R) {
@@ -901,8 +899,6 @@
 	compound(NULL, NULL, NULL);
 	popctx();
 	emit(OEFUN, NULL);
-	free(sym->u.pars);
-	sym->u.pars = NULL;
 	flushtypes();
 	curfun = ocurfun;
 }
--- /dev/null
+++ b/tests/execute/0111-doubledef.c
@@ -1,0 +1,9 @@
+int foo(void);
+int foo(void);
+#define FOO 0
+
+int
+main()
+{
+	return FOO;
+}
--- a/tests/execute/scc-tests.lst
+++ b/tests/execute/scc-tests.lst
@@ -101,3 +101,4 @@
 0108-bug.c
 0109-struct.c
 0110-typedefcast.c
+0111-doubledef.c