scc

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

commit a65f71ddd0bb0fae2868884002807ac166b32909
parent 52b6ff8b2915bb64d194191dfdeda6539e71fa8f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  5 Apr 2022 06:10:23 +0200

cc1: Add spaces between tokens from macro arguments

If we paste arguments without spaces then we concarenate them.

Diffstat:
Msrc/cmd/cc/cc1/cpp.c | 7++++---
Atests/cc/execute/0205-cpparg.c | 13+++++++++++++
Mtests/cc/execute/scc-tests.lst | 1+
3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/src/cmd/cc/cc1/cpp.c b/src/cmd/cc/cc1/cpp.c @@ -181,14 +181,15 @@ expandarg(char *arg, char *buf, int bufsiz) addinput(filenam, NULL, xstrdup(arg), FAIL); - for (siz = 0; next() != EOFTOK; siz += yylen) { - if (yylen > bufsiz-1) { + for (siz = 0; next() != EOFTOK; siz += yylen+1) { + if (yylen > bufsiz-2) { siz = -1; break; } memcpy(buf, yytext, yylen); - bufsiz -= yylen; + bufsiz -= yylen + 1; buf += yylen; + *buf++ = ' '; } *buf = '\0'; diff --git a/tests/cc/execute/0205-cpparg.c b/tests/cc/execute/0205-cpparg.c @@ -0,0 +1,13 @@ +#define TOLOWER(c) ((((unsigned)c) - 'A' < 26) ? ((c) | 32) : (c)) + +int +main(void) +{ + char c, *s = "Bla"; + + c = TOLOWER((unsigned char)*s); + if (c != 'b') + return 1; + + return 0; +} diff --git a/tests/cc/execute/scc-tests.lst b/tests/cc/execute/scc-tests.lst @@ -195,3 +195,4 @@ 0202-variadic.c [TODO] 0203-comment.c 0204-cast.c +0205-cpparg.c