Hi,
On Fri, Nov 23, 2007 at 09:15:12AM +0800, Feng Nauh wrote:
> for example:
>
> // lf_macro.c
> #define M(a,b) (a+b)
> int main() {
> return M(1,
> 2);
> }
>
> "tcc -E lf_macro.c", then tcc enter an endless loop; but compile is ok.
Yep, the problem seems to be that within tcc_preprocess parse_flags is
ORed with PARSE_FLAG_LINEFEED this causes an endless loop in
macro_subst_tok (line 3268) because next_nomacro will always set tok to
TOK_LINEFEED.
There is a debian bug report[1] with a similar porblem but the mentioned
patch looks a bit bogus to me. Attached is my workaround.
Marc
[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=435027
--
Marc Andre Tanner >< http://www.brain-dump.org/ >< GPG key: CF7D56C0
diff -r 218d28dbcf0b tcc.c
--- a/tcc.c Fri Nov 16 12:16:14 2007 +0800
+++ b/tcc.c Sat Nov 24 13:10:54 2007 +0100
@@ -3264,6 +3264,9 @@ static int macro_subst_tok(TokenString *
get_tok_str(s->v, 0));
tok_str_new(&str);
parlevel = 0;
+ /* XXX: hack to avoid an endless loop in -E (preprocess) mode */
+ int saved_parse_flags = parse_flags;
+ parse_flags &= ~PARSE_FLAG_LINEFEED;
/* NOTE: non zero sa->t indicates VA_ARGS */
while ((parlevel > 0 ||
(tok != ')' &&
@@ -3276,6 +3279,7 @@ static int macro_subst_tok(TokenString *
tok_str_add2(&str, tok, tok_flags, &tokc);
next_nomacro();
}
+ parse_flags = saved_parse_flags;
tok_str_add(&str, 0, 0);
sym_push2(&args, sa->v & ~SYM_FIELD, sa->type.t, (int)str.str);
sa = sa->next;
_______________________________________________
Tinycc-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/tinycc-devel