diff options
author | Nathan Sidwell <nathan@acm.org> | 2020-10-08 12:11:37 -0700 |
---|---|---|
committer | Nathan Sidwell <nathan@acm.org> | 2020-10-08 12:16:21 -0700 |
commit | d1c566d72d9361b37213881222c7e2713cdf05b7 (patch) | |
tree | aa7640d9fb655ceb26caddbd903344fb6662a1e1 /libcpp/files.c | |
parent | cd23ed8af236db2d28314e0652d04e5a0e1540b6 (diff) | |
download | gcc-d1c566d72d9361b37213881222c7e2713cdf05b7.zip gcc-d1c566d72d9361b37213881222c7e2713cdf05b7.tar.gz gcc-d1c566d72d9361b37213881222c7e2713cdf05b7.tar.bz2 |
libcpp: Directly peek for initial line marker
Using the tokenizer to sniff for an initial line marker for
preprocessed input is a little brittle, particularly with
-fdirectives-only. If there is no marker we'll happily munch initial
comments. This patch directly sniffs the buffer. This is safe
because the initial line marker was machine generated and must be
right at the beginning of the file. Anything else is not such a line
marker. The same is true for the initial directory marker. For that
tokenizing the string is simplest, but at that point it's either a
regular line marker or a directory marker. If it's a regular marker,
unwinding tokens is fine.
libcpp/
* internal.h (enum include_type): Rename IT_MAIN_INJECT to
IT_PRE_MAIN.
* init.c (cpp_read_main_file): If there is no line marker, adjust
the initial line marker.
(read_original_filename): Return bool, peek the buffer directly
before trying to tokenize.
(read_original_directory): Likewise. Directly prod the string
literal.
* files.c (_cpp_stack_file): Adjust for IT_PRE_MAIN change.
Diffstat (limited to 'libcpp/files.c')
-rw-r--r-- | libcpp/files.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libcpp/files.c b/libcpp/files.c index b890b8e..5af4136 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -948,10 +948,12 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type, /* Add line map and do callbacks. */ _cpp_do_file_change (pfile, LC_ENTER, file->path, - /* With preamble injection, start on line zero, so - the preamble doesn't appear to have been - included from line 1. */ - type == IT_MAIN_INJECT ? 0 : 1, sysp); + /* With preamble injection, start on line zero, + so the preamble doesn't appear to have been + included from line 1. Likewise when + starting preprocessed, we expect an initial + locating line. */ + type == IT_PRE_MAIN ? 0 : 1, sysp); return true; } |