commit 0fc57e51871e09511d6135791773b7e0ba26aaf6
parent 4a268a57f3be8c3af8c85d03ab13cdb17d0979c6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Wed, 11 May 2016 12:57:56 +0200
[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.
Diffstat:
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/cc1/cpp.c b/cc1/cpp.c
@@ -293,16 +293,18 @@ substitute:
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 @@ getpars(Symbol *args[NR_MACROARG])
}
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 @@ define(void)
}
namespace = NS_IDEN; /* Avoid polution in NS_CPP */
- next();
if ((n = getpars(args)) == NR_MACROARG)
goto delete;
sprintf(buff, "%02d#", n);