# HG changeset patch # User Rob Landley # Date 1189031802 18000 # Node ID 5ecdf063c480fe0ea5dfc4f38620f0aacfd08338 # Parent 46f5437276f3a147a09f45a6f52ce24bf39367d0 Joshua Phillips fixed backslash parsing between #ifdefs (\garbage should not produce an error inside a disabled #ifdef). I tweaked it a bit and added a test case. diff -r 46f5437276f3 -r 5ecdf063c480 tcc.c --- a/tcc.c Wed Sep 05 17:32:02 2007 -0500 +++ b/tcc.c Wed Sep 05 17:36:42 2007 -0500 @@ -1079,25 +1079,30 @@ ch = handle_eob(); } +/* space excluding newline */ +static inline int is_space(int ch) +{ + return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; +} + /* handle '\[\r]\n' */ -static void handle_stray(void) +static int handle_stray_noerror(void) { while (ch == '\\') { inp(); + while (is_space(ch)) inp(); if (ch == '\n') { file->line_num++; inp(); - } else if (ch == '\r') { - inp(); - if (ch != '\n') - goto fail; - file->line_num++; - inp(); - } else { - fail: - error("stray '\\' in program"); - } - } + } else return 1; + } + return 0; +} + +static void handle_stray(void) +{ + if(handle_stray_noerror()) + error("stray '\\' in program"); } /* skip the stray and handle the \\n case. Output an error if @@ -1270,12 +1275,6 @@ #define cinp minp -/* space exlcuding newline */ -static inline int is_space(int ch) -{ - return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r'; -} - static inline void skip_spaces(void) { while (is_space(ch)) @@ -1377,9 +1376,8 @@ if (c == CH_EOF) { expect("#endif"); } else if (c == '\\') { - /* XXX: incorrect: should not give an error */ ch = file->buf_ptr[0]; - handle_stray(); + handle_stray_noerror(); } p = file->buf_ptr; goto redo_no_start; diff -r 46f5437276f3 -r 5ecdf063c480 tests/tcctest.c --- a/tests/tcctest.c Wed Sep 05 17:32:02 2007 -0500 +++ b/tests/tcctest.c Wed Sep 05 17:36:42 2007 -0500 @@ -2176,3 +2176,11 @@ // Make sure compound literals work outside functions. struct point { int X; int Y; } *test = &((struct point){1,1}); + + +// Make sure \garbage isn't an error in #ifdefs. +#ifdef NOT_DEFINED +# include +# include +#endif +