tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] bug report / preprocessor / string literals


From: Bernhard Fischer
Subject: Re: [Tinycc-devel] bug report / preprocessor / string literals
Date: Mon, 13 Feb 2006 10:06:11 +0100
User-agent: Mutt/1.5.11

On Fri, Jan 27, 2006 at 12:16:20PM +0100, address@hidden wrote:
>Hi @,
>
>There seems to be a bug in the preprocessor when using # to create string
>literals.
>
>The following source ...
>
>#define printxml(xml) printf(#xml)
>#define nl printf("\n")
>
>int main() {
>        printxml(
><html>
></html>
>);
>        nl;
>        return 0;
>}
>
>... compiled with tcc yields the following output:
>
>< html > < / html >
>
>The same source compiled with cc yields the following (correct) output:
>
><html> </html>
>
>This may be easy to fix, but I'd need a hint where to look in the source,
>not time to go searching...

To me it looks like these args should not be tokenized but each read in
one slurp (until eol or end of arg -- '\'' or ')').

Didn't look into this yet, but perhaps look at parse_define() and
next_nomacro1(). I'm not certain if adding a TOKEN_FLAG for string
literals is ok (as said, i didn't look into it):

@@ -320,7 +320,8 @@ static CString tokcstr; /* current parse
 static int tok_flags;
 #define TOK_FLAG_BOL   0x0001 /* beginning of line before */
 #define TOK_FLAG_BOF   0x0002 /* beginning of file before */
-#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting
#ifdef */
+#define TOK_FLAG_ENDIF 0x0004 /* an endif was found matching starting
#ifdef */
+#define TOK_FLAG_STR   0x0008 /* is a string literal */
 
 static int *macro_ptr, *macro_ptr_allocated;
 static int *unget_saved_macro_ptr;


and then flagging them
@@ -3577,7 +3580,7 @@ static inline void next_nomacro1(void)
         if ((tok_flags & TOK_FLAG_BOL) && 
             (parse_flags & PARSE_FLAG_PREPROCESS)) {
             file->buf_ptr = p;
-            preprocess(tok_flags & TOK_FLAG_BOF);
+            preprocess(tok_flags & (TOK_FLAG_BOF | TOK_FLAG_STR));
             p = file->buf_ptr;
             goto redo_no_start;
         } else {
@@ -3951,7 +3954,7 @@ static int *macro_arg_subst(Sym **nested
                 st = (int *)s->c;
                 notfirst = 0;
                 while (*st) {
-                    if (notfirst)
+                    if (notfirst && (parse_flags &
PARSE_FLAG_PREPROCESS))
                         cstr_ccat(&cstr, ' ');
                     TOK_GET(t, st, cval);
                     cstr_cat(&cstr, get_tok_str(t, &cval));

HTH,
Bernhard




reply via email to

[Prev in Thread] Current Thread [Next in Thread]