scc

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

commit b24acc5c7df6b763932c59376817693ed292cd68
parent a8aff41b8b4d91534abe9a039681fdb2ca7a0399
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date:   Wed,  8 Apr 2026 16:32:37 +0200

cc1: Fix + 1 error getting char constants in getdefs()

Character or string constants are parsed using next() and it put the
current pointer of the input placed in the next character after the
end of the token, and like the main loop was incrementing the current
pointer then we were jumping over one character.

Diffstat:
Msrc/cmd/scc-cc/cc1/cpp.c | 1+
Atests/cc/execute/0260-macro.c | 12++++++++++++
Mtests/cc/execute/scc-tests.lst | 1+
3 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/cmd/scc-cc/cc1/cpp.c b/src/cmd/scc-cc/cc1/cpp.c @@ -607,6 +607,7 @@ getdefs(Symbol *args[NR_MACROARG], int nargs, char *buffer, size_t bufsiz) token = yytoken; s = yytext; len = yylen; + --input->p; } if (sym && nargs > 0) { diff --git a/tests/cc/execute/0260-macro.c b/tests/cc/execute/0260-macro.c @@ -0,0 +1,12 @@ + +#define f1(c) c +#define f2() f1('\n') +#define f3() f1("h") + +int +main() +{ + int a = f2() == '\n'; + + return !(a == 1); +} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -250,3 +250,4 @@ 0257-main.c 0258-variadic.c 0259-multichar.c +0260-macro.c