diff options
author | Joseph Myers <joseph@codesourcery.com> | 2009-04-18 18:36:28 +0100 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2009-04-18 18:36:28 +0100 |
commit | c7f9c0b9835fc77208bddffec0ba71d33fb425fa (patch) | |
tree | 59684b555702b1b2456e3b64f86fd190e1b48332 | |
parent | b8add5942c0ce71990233b594d5f0bdec31d73c8 (diff) | |
download | gcc-c7f9c0b9835fc77208bddffec0ba71d33fb425fa.zip gcc-c7f9c0b9835fc77208bddffec0ba71d33fb425fa.tar.gz gcc-c7f9c0b9835fc77208bddffec0ba71d33fb425fa.tar.bz2 |
re PR preprocessor/39646 (__FILE__ breaks for empty file name)
libcpp:
PR preprocessor/39646
* include/line-map.h (enum lc_reason): Add LC_RENAME_VERBATIM.
* line-map.c (linemap_add): Handle LC_RENAME_VERBATIM.
* directives.c (do_line, do_linemarker): Use LC_RENAME_VERBATIM in
place of LC_RENAME.
gcc/testsuite:
* gcc.dg/cpp/line8.c: New test.
From-SVN: r146319
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/cpp/line8.c | 10 | ||||
-rw-r--r-- | libcpp/ChangeLog | 8 | ||||
-rw-r--r-- | libcpp/directives.c | 4 | ||||
-rw-r--r-- | libcpp/include/line-map.h | 5 | ||||
-rw-r--r-- | libcpp/line-map.c | 5 |
6 files changed, 32 insertions, 5 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 58ea487..075c7b5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2009-04-18 Joseph Myers <joseph@codesourcery.com> + PR preprocessor/39646 + * gcc.dg/cpp/line8.c: New test. + +2009-04-18 Joseph Myers <joseph@codesourcery.com> + PR preprocessor/39647 * gcc.dg/cpp/line7.c: New test. diff --git a/gcc/testsuite/gcc.dg/cpp/line8.c b/gcc/testsuite/gcc.dg/cpp/line8.c new file mode 100644 index 0000000..5aeb26c --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/line8.c @@ -0,0 +1,10 @@ +/* Test that "" is not specially interpreted as "<stdin>" in a #line + directive. PR 39646. */ + +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors" } */ + +extern int x; + +#line 24 "" +extern char z[sizeof __FILE__ == 1]; diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index ce7bbe0..ab72fa6 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,5 +1,13 @@ 2009-04-18 Joseph Myers <joseph@codesourcery.com> + PR preprocessor/39646 + * include/line-map.h (enum lc_reason): Add LC_RENAME_VERBATIM. + * line-map.c (linemap_add): Handle LC_RENAME_VERBATIM. + * directives.c (do_line, do_linemarker): Use LC_RENAME_VERBATIM in + place of LC_RENAME. + +2009-04-18 Joseph Myers <joseph@codesourcery.com> + PR preprocessor/39647 * directives.c (check_eol): Add parameter expand. (do_undef, parse_include, do_line, do_linemarker, do_ident, diff --git a/libcpp/directives.c b/libcpp/directives.c index 9cb8506..9e26732 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -924,7 +924,7 @@ do_line (cpp_reader *pfile) } skip_rest_of_line (pfile); - _cpp_do_file_change (pfile, LC_RENAME, new_file, new_lineno, + _cpp_do_file_change (pfile, LC_RENAME_VERBATIM, new_file, new_lineno, map_sysp); } @@ -940,7 +940,7 @@ do_linemarker (cpp_reader *pfile) const char *new_file = map->to_file; linenum_type new_lineno; unsigned int new_sysp = map->sysp; - enum lc_reason reason = LC_RENAME; + enum lc_reason reason = LC_RENAME_VERBATIM; int flag; bool wrapped; diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 501a193..56ab79a 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -31,8 +31,9 @@ along with this program; see the file COPYING3. If not see when including a new file, e.g. a #include directive in C. LC_LEAVE is when reaching a file's end. LC_RENAME is when a file name or line number changes for neither of the above reasons - (e.g. a #line directive in C). */ -enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME}; + (e.g. a #line directive in C); LC_RENAME_VERBATIM is like LC_RENAME + but a filename of "" is not specially interpreted as standard input. */ +enum lc_reason {LC_ENTER = 0, LC_LEAVE, LC_RENAME, LC_RENAME_VERBATIM}; /* The type of line numbers. */ typedef unsigned int linenum_type; diff --git a/libcpp/line-map.c b/libcpp/line-map.c index cce699f..553cc2a 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -109,9 +109,12 @@ linemap_add (struct line_maps *set, enum lc_reason reason, map = &set->maps[set->used]; - if (to_file && *to_file == '\0') + if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM) to_file = "<stdin>"; + if (reason == LC_RENAME_VERBATIM) + reason = LC_RENAME; + /* If we don't keep our line maps consistent, we can easily segfault. Don't rely on the client to do it for us. */ if (set->depth == 0) |