shithub: scc

Download patch

ref: 57daf2b20c49488d3d5771239ee302a0afb6004a
parent: fee8c92d2df603a2d001eeabb1de5a4e01e1ed40
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Jan 16 08:31:48 EST 2017

[cc1] Fix character constants in macros

Character tokens were not taking a correct yytext, which
was generating a problem in getdefs() because this function
is based in taking the text of the tokens from yytext.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -182,11 +182,10 @@
 	return 1;
 }
 
-/* FIXME: characters in the definition break the macro definition */
 static size_t
 copymacro(char *buffer, char *s, size_t bufsiz, char *arglist[])
 {
-	char prevc, c, *p, *arg, *bp = buffer;
+	char delim, prevc, c, *p, *arg, *bp = buffer;
 	size_t size;
 
 	for (prevc = '\0'; c = *s; prevc = c, ++s) {
@@ -198,8 +197,13 @@
 				++s;
 		case '#':
 			break;
+		case '\'':
+			delim = '\'';
+			goto search_delim;
 		case '\"':
-			for (p = s; *++s != '"'; )
+			delim = '"';
+		search_delim:
+			for (p = s; *++s != delim; )
 				/* nothing */;
 			size = s - p + 1;
 			if (size > bufsiz)
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -467,9 +467,11 @@
 static unsigned
 character(void)
 {
-	static char c;
+	char c, *p;
 	Symbol *sym;
+	size_t size;
 
+	p = input->p;
 	if ((c = *++input->p) == '\\')
 		c = escape();
 	else
@@ -479,6 +481,10 @@
 		error("invalid character constant");
 	else
 		++input->p;
+
+	size = input->p - p;
+	memcpy(yytext, p, size);
+	yytext[size] = '\0';
 
 	sym = newsym(NS_IDEN, NULL);
 	sym->u.i = c;