Mercurial > hg > qcc
changeset 472:5ecdf063c480
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.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 05 Sep 2007 17:36:42 -0500 |
parents | 46f5437276f3 |
children | ec2b47ce2530 |
files | tcc.c tests/tcctest.c |
diffstat | 2 files changed, 26 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- 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;
--- 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 <windows.h> +# include <gl\glaux.h> +#endif +