From: borutr Date: Wed, 20 Dec 2006 22:43:09 +0000 (+0000) Subject: * support/cpp2/cpphash.h, support/cpp2/cpplex.c: fixed bug #982435 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;ds=sidebyside;h=3cd209ff7a929f45b1ceea53ad020ccddecf3071;p=fw%2Fsdcc * support/cpp2/cpphash.h, support/cpp2/cpplex.c: fixed bug #982435 * support/regression/tests/bug-1351710.c: renamed from bug-1351710.c, added regression test for bug #982435 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4520 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 30655baf..45ae76dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-12-20 Borut Razem + + * support/cpp2/cpphash.h, support/cpp2/cpplex.c: fixed bug #982435 + * support/regression/tests/bug-1351710.c: renamed from bug-1351710.c, + added regression test for bug #982435 + 2006-12-18 Borut Razem * src/SDCCutil.c: fixed a bug in (get_pragma_token) diff --git a/support/cpp2/cpphash.h b/support/cpp2/cpphash.h index 0643f93b..d619fcbf 100644 --- a/support/cpp2/cpphash.h +++ b/support/cpp2/cpphash.h @@ -43,6 +43,10 @@ typedef unsigned char uchar; || (((prevc) == 'p' || (prevc) == 'P') \ && CPP_OPTION (pfile, extended_numbers)))) +/* Test if a X or x is valid within a preprocessing number. */ +#define VALID_HEX(c, prevc) \ + (((c) == 'X' || (c) == 'x') && (prevc) == '0') + #define CPP_OPTION(PFILE, OPTION) ((PFILE)->opts.OPTION) #define CPP_BUFFER(PFILE) ((PFILE)->buffer) #define CPP_BUF_COLUMN(BUF, CUR) ((CUR) - (BUF)->line_base + (BUF)->col_adjust) diff --git a/support/cpp2/cpplex.c b/support/cpp2/cpplex.c index b5b8ba72..b802ed60 100644 --- a/support/cpp2/cpplex.c +++ b/support/cpp2/cpplex.c @@ -577,26 +577,42 @@ parse_slow (pfile, cur, number_p, plen) if (c == '?' || c == '\\') c = skip_escaped_newlines (pfile); - if (!is_idchar (c)) - { - if (!number_p) - break; - if (c != '.' && !VALID_SIGN (c, prevc)) + if (number_p) + { + if (!ISXDIGIT (c) && c != '.' && !VALID_SIGN (c, prevc) && !VALID_HEX (c, prevc)) break; - } - /* Handle normal identifier characters in this loop. */ - do - { - prevc = c; - obstack_1grow (stack, c); + obstack_1grow (stack, c); - if (c == '$') - saw_dollar++; + base = cur = buffer->cur; + while (ISXDIGIT (*cur)) + ++cur; - c = *buffer->cur++; - } - while (is_idchar (c)); + if (cur != base) + obstack_grow (stack, base, cur - base); + + prevc = cur[-1]; + c = *cur++; + buffer->cur = cur; + } + else + { + if (!is_idchar (c)) + break; + + /* Handle normal identifier characters in this loop. */ + do + { + prevc = c; + obstack_1grow (stack, c); + + if (c == '$') + saw_dollar++; + + c = *buffer->cur++; + } + while (is_idchar (c)); + } } /* Step back over the unwanted char. */ @@ -628,7 +644,8 @@ parse_number (pfile, number, leading_period) /* Fast-path loop. Skim over a normal number. N.B. ISIDNUM does not include $. */ cur = pfile->buffer->cur; - while (ISIDNUM (*cur) || *cur == '.' || VALID_SIGN (*cur, cur[-1])) + + while (ISXDIGIT (*cur) || *cur == '.' || VALID_SIGN (*cur, cur[-1]) || VALID_HEX (*cur, cur[-1])) cur++; /* Check for slow-path cases. */ diff --git a/support/regression/tests/bug-1351710.c b/support/regression/tests/bug-1351710.c deleted file mode 100644 index 20147a56..00000000 --- a/support/regression/tests/bug-1351710.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - bug-1351710.c -*/ - -#include - -const char * -const_str(void) -{ -return "A" - - - -/* just for testing, actually nop */ -#pragma save - - - - - -"B"; -#pragma restore -} - -void -testBug(void) -{ - const char *str = const_str(); -} diff --git a/support/regression/tests/preproc.c b/support/regression/tests/preproc.c new file mode 100644 index 00000000..110a69f1 --- /dev/null +++ b/support/regression/tests/preproc.c @@ -0,0 +1,44 @@ +/* + preproc.c +*/ + +#include + +/* + * test for bug 135170 + */ +const char * +const_str(void) +{ +return "A" + + + +/* just for testing, actually nop */ +#pragma save + + + + + +"B"; +#pragma restore +} + +/* + * test for bug 982435 + */ +#if !defined (__GNUC__) && !defined (_MSC_VER) +/* since this fails on GCC cpp and MSVC cl -E... */ +#define LO_B(x) ((x) & 0xff) + +unsigned char +hexeminus(void) +{ +unsigned char a=0x\ +fe\ +-\ +LO_B(3); +return a; +} +#endif