ref: a65f71ddd0bb0fae2868884002807ac166b32909
parent: 52b6ff8b2915bb64d194191dfdeda6539e71fa8f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Apr 5 02:10:23 EDT 2022
cc1: Add spaces between tokens from macro arguments If we paste arguments without spaces then we concarenate them.
--- a/src/cmd/cc/cc1/cpp.c
+++ b/src/cmd/cc/cc1/cpp.c
@@ -181,14 +181,15 @@
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';
--- /dev/null
+++ b/tests/cc/execute/0205-cpparg.c
@@ -1,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;
+}
--- 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