commit 7d04db9269280cbbf13a16514fd2a232474b99c2
parent 54cee0dcbfec165ffa4eecdae01d2b9ebdc4b211
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 13 Nov 2021 08:17:23 +0100
cc1: Expand macro parameters
Macro parameters must be expanded before the macro itself is expanded.
Diffstat:
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c
@@ -154,7 +154,6 @@ parsepars(char *buffer, char **listp, int nargs)
if (ahead() != '(' && nargs > 0)
return 0;
- disexpand = 1;
next();
n = 0;
argp = buffer;
@@ -257,7 +256,13 @@ expand(Symbol *sym)
size_t elen;
int n, i;
char *s = sym->u.s;
- char *arglist[NR_MACROARG], arguments[INPUTSIZ], buffer[INPUTSIZ];
+ char *arglist[NR_MACROARG];
+ char arguments[INPUTSIZ], buffer[INPUTSIZ];
+
+ DBG("MACRO '%s' detected %d %d", sym->name, disexpand, sym->hide);
+
+ if (disexpand || sym->hide)
+ return 0;
macroname = sym->name;
if (sym == symfile) {
diff --git a/src/cmd/cc/cc1/lex.c b/src/cmd/cc/cc1/lex.c
@@ -614,7 +614,7 @@ iden(void)
input->p = p;
tok2str();
if ((sym = lookup(NS_CPP, yytext, NOALLOC)) != NULL) {
- if (!disexpand && !sym->hide && expand(begin, sym))
+ if (expand(sym))
return next();
}
sym = lookup(namespace, yytext, ALLOC);