shithub: scc

Download patch

ref: b4bf584770cafcdad5420b6e3b8b80b386e6b441
parent: 52eb16bd024aab0ee1430f48f3a41c689359d8f2
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed May 11 08:57:56 EDT 2016

[cc1] Fix parsing of function alike macros

A macro is a function alike macro if just after the name of
the macro there is a '('. Before this commit we were detecting
this situation only looking for tokens, but in this case we
need to check directly in the input line and see if '(' is
not separated from the macro name.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -293,16 +293,18 @@
 static int
 getpars(Symbol *args[NR_MACROARG])
 {
-	int n = -1;
+	int n, c;
 	Symbol *sym;
 
-	if (!accept('('))
-		return n;
-	++n;
+	c = *input->p;
+	next();
+	if (c != '(')
+		return -1;
+	next(); /* skip the '(' */
 	if (accept(')'))
-		return n;
+		return 0;
 
-	do {
+	for (n = 0; ; ++n) {
 		if (n == NR_MACROARG) {
 			cpperror("too much parameters in macro");
 			return NR_MACROARG;
@@ -313,9 +315,11 @@
 		}
 		sym = install(NS_IDEN, yylval.sym);
 		sym->flags |= SUSED;
-		args[n++] = sym;
+		args[n] = sym;
 		next();
-	} while (accept(','));
+		if (!accept(','))
+			break;
+	}
 	expect(')');
 
 	return n;
@@ -399,7 +403,6 @@
 	}
 
 	namespace = NS_IDEN;       /* Avoid polution in NS_CPP */
-	next();
 	if ((n = getpars(args)) == NR_MACROARG)
 		goto delete;
 	sprintf(buff, "%02d#", n);