libcpp: misc fixes from Apple's GCC.

Fixes some bugs detected by Apple:
#error with unmatched quotes
pragma mark

Obtained from:	Apple GCC 4.2 - 5553
MFC after:	1 week
This commit is contained in:
Pedro F. Giffuni 2014-01-05 00:32:38 +00:00
parent b3a6fedaec
commit e1b3bb5380
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=260310
6 changed files with 47 additions and 2 deletions

View file

@ -873,7 +873,9 @@ enum machopic_addr_class {
#define DARWIN_REGISTER_TARGET_PRAGMAS() \
do { \
c_register_pragma (0, "mark", darwin_pragma_ignore); \
/* APPLE LOCAL begin pragma mark 5614511 */ \
/* Removed mark. */ \
/* APPLE LOCAL end pragma mark 5614511 */ \
c_register_pragma (0, "options", darwin_pragma_options); \
c_register_pragma (0, "segment", darwin_pragma_ignore); \
c_register_pragma (0, "unused", darwin_pragma_unused); \

View file

@ -3,6 +3,11 @@
Radar 6121572
* charset.c (_cpp_convert_input): Don't read to.text[-1].
2008-05-01 Mike Stump <mrs@apple.com>
Radar 5774975
* charset.c (_cpp_convert_input): Eat UTF-8 BOM.
2005-02-17 Devang Patel <dpatel@apple.com>
Radar 3958387

View file

@ -1597,6 +1597,17 @@ _cpp_convert_input (cpp_reader *pfile, const char *input_charset,
input_cset = init_iconv_desc (pfile, SOURCE_CHARSET, input_charset);
if (input_cset.func == convert_no_conversion)
{
/* APPLE LOCAL begin UTF-8 BOM 5774975 */
/* Eat the UTF-8 BOM. */
if (len >= 3
&& input[0] == 0xef
&& input[1] == 0xbb
&& input[2] == 0xbf)
{
memmove (&input[0], &input[3], size-3);
len -= 3;
}
/* APPLE LOCAL end UTF-8 BOM 5774975 */
to.text = input;
to.asize = size;
to.len = len;

View file

@ -991,7 +991,11 @@ do_diagnostic (cpp_reader *pfile, int code, int print_dir)
if (print_dir)
fprintf (stderr, "#%s ", pfile->directive->name);
pfile->state.prevent_expansion++;
/* APPLE LOCAL #error with unmatched quotes 5607574 */
pfile->state.in_diagnostic++;
cpp_output_line (pfile, stderr);
/* APPLE LOCAL #error with unmatched quotes 5607574 */
pfile->state.in_diagnostic--;
pfile->state.prevent_expansion--;
}
}
@ -1173,12 +1177,25 @@ cpp_register_deferred_pragma (cpp_reader *pfile, const char *space,
}
}
/* APPLE LOCAL begin pragma mark 5614511 */
/* Handle #pragma mark. */
static void
do_pragma_mark (cpp_reader *pfile)
{
++pfile->state.skipping;
skip_rest_of_line (pfile);
--pfile->state.skipping;
}
/* APPLE LOCAL end pragma mark 5614511 */
/* Register the pragmas the preprocessor itself handles. */
void
_cpp_init_internal_pragmas (cpp_reader *pfile)
{
/* Pragmas in the global namespace. */
register_pragma_internal (pfile, 0, "once", do_pragma_once);
/* APPLE LOCAL pragma mark 5614511 */
register_pragma_internal (pfile, 0, "mark", do_pragma_mark);
/* New GCC-specific pragmas should be put in the GCC namespace. */
register_pragma_internal (pfile, "GCC", "poison", do_pragma_poison);

View file

@ -220,6 +220,11 @@ struct lexer_state
/* Nonzero if the deferred pragma being handled allows macro expansion. */
unsigned char pragma_allow_expansion;
/* APPLE LOCAL begin #error with unmatched quotes 5607574 */
/* Nonzero when handling #error and #warning to allow unmatched quotes. */
unsigned char in_diagnostic;
/* APPLE LOCAL end #error with unmatched quotes 5607574 */
};
/* Special nodes - identifiers with predefined significance. */

View file

@ -658,7 +658,12 @@ lex_string (cpp_reader *pfile, cpp_token *token, const uchar *base)
cpp_error (pfile, CPP_DL_WARNING,
"null character(s) preserved in literal");
if (type == CPP_OTHER && CPP_OPTION (pfile, lang) != CLK_ASM)
/* APPLE LOCAL begin #error with unmatched quotes 5607574 */
if (type == CPP_OTHER
&& CPP_OPTION (pfile, lang) != CLK_ASM
&& !pfile->state.in_diagnostic
&& !pfile->state.skipping)
/* APPLE LOCAL end #error with unmatched quotes 5607574 */
cpp_error (pfile, CPP_DL_PEDWARN, "missing terminating %c character",
(int) terminator);