[preprocessor/91639] #includes at EOF
https://gcc.gnu.org/ml/gcc-patches/2019-09/msg00280.html libcpp/ PR preprocessor/91639 * directives.c (do_include_common): Tell lexer we're a #include. * files.c (_cpp_stack_file): Lexer will have always incremented. * internal.h (struct cpp_context): Extend in_directive's semantics. * lex.c (_cpp_lex_direct): Increment line for final \n when lexing for an ISO #include. * line-map.c (linemap_line_start): Remember if we overflowed. gcc/testsuite/ PR preprocessor/91639 * c-c++-common/cpp/pr91639.c: New. * c-c++-common/cpp/pr91639-one.h: New. * c-c++-common/cpp/pr91639-two.h: New. From-SVN: r275402
This commit is contained in:
parent
e7414688f1
commit
056f95ec95
10 changed files with 58 additions and 22 deletions
|
@ -938,25 +938,16 @@ _cpp_stack_file (cpp_reader *pfile, _cpp_file *file, include_type type,
|
|||
pfile->mi_valid = true;
|
||||
pfile->mi_cmacro = 0;
|
||||
|
||||
/* Compensate for the increment in linemap_add that occurs when in
|
||||
do_file_change. In the case of a normal #include, we're
|
||||
currently at the start of the line *following* the #include. A
|
||||
separate location_t for this location makes no sense (until we do
|
||||
the LC_LEAVE), and complicates LAST_SOURCE_LINE_LOCATION. This
|
||||
does not apply if we found a PCH file (in which case linemap_add
|
||||
is not called) or we were included from the command-line. In the
|
||||
case that the #include is the last line in the file,
|
||||
highest_location still points to the current line, not the start
|
||||
of the next line, so we do not decrement in this case. See
|
||||
plugin/location-overflow-test-pr83173.h for an example. */
|
||||
bool decremented = false;
|
||||
if (file->pchname == NULL && file->err_no == 0 && type < IT_DIRECTIVE_HWM)
|
||||
{
|
||||
decremented = (pfile->line_table->highest_line
|
||||
== pfile->line_table->highest_location);
|
||||
if (decremented)
|
||||
pfile->line_table->highest_location--;
|
||||
}
|
||||
/* In the case of a normal #include, we're now at the start of the
|
||||
line *following* the #include. A separate location_t for this
|
||||
location makes no sense, until we do the LC_LEAVE.
|
||||
|
||||
This does not apply if we found a PCH file, we're not a regular
|
||||
include, or we ran out of locations. */
|
||||
if (file->pchname == NULL
|
||||
&& type < IT_DIRECTIVE_HWM
|
||||
&& pfile->line_table->highest_location != LINE_MAP_MAX_LOCATION - 1)
|
||||
pfile->line_table->highest_location--;
|
||||
|
||||
/* Add line map and do callbacks. */
|
||||
_cpp_do_file_change (pfile, LC_ENTER, file->path, 1, sysp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue