scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit d0b2ef66dfa60adc27c6c9a7f89e6954afdae838
parent 9e1c9a318ff8b791218b93cfb1491fdb32bf2d21
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed,  1 Mar 2023 23:01:42 +0100

cc1: Improve concatenation detect

The case for the second operator in macro concatenation was
failling due to wrong pointer arithmetic that was checking
for spaces from the first character of the macro parameter
that is just a delimiter for macro parameters.

Diffstat:
Msrc/cmd/cc/cc1/cpp.c | 6+++---
Mtests/cc/execute/0223-macro.c | 3++-
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c @@ -189,7 +189,7 @@ concatoper(char *def, char *cur) { char *s; - for (s = cur + 3; isspace(*s); ++s) + for (s = cur + 4; isspace(*s); ++s) ; if (*s == CONCAT) return 1; @@ -315,13 +315,13 @@ copymacro(Macro *mp) break; case MACROPAR: /* parameter substitution */ - arg = mp->arglist[atoi(++s)]; + arg = mp->arglist[atoi(s+1)]; size = expandarg(arg, mp->def, s, bp, bufsiz); if (size < 0) goto expansion_too_long; bp += size; bufsiz -= size; - s += 2; + s += 3; break; default: if (bufsiz-- == 0) diff --git a/tests/cc/execute/0223-macro.c b/tests/cc/execute/0223-macro.c @@ -1,9 +1,10 @@ #define foo [] #define cat(x, y) x##y int cat(foo,_); +int cat(a,foo); int main() { - return foo_; + return foo_ || afoo; }