https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83173
Bug ID: 83173 Summary: C preprocessor generates incorrect linemarkers Product: gcc Version: 7.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: mgulick at mathworks dot com Target Milestone: --- Created attachment 42724 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42724&action=edit invalid linemarker reproduction source code GCC is generating incorrect line markers when processing source files with a large number of includes (e.g. where the internal line map's source location is greater than LINE_MAP_MAX_LOCATION_WITH_COLS. This results in warnings from gcc when it compiles this previously preprocessed output. It also results in gcc generating incorrect line mappings in the debug symbols, as well as producing compiler warnings and errors that are associated with the wrong file name and line number. This invalid line marker is generated for include files that have a '#include' as the last line in the file. Simply adding an additional newline after the last include will eliminate this issue. This issue only occurs when the preprocessor is run as a separate phase, as when using -save-temps, -no-integrated-cpp, or -E (as is used by distcc). See also: https://gcc.gnu.org/ml/gcc-help/2017-11/msg00073.html I have tested gcc 6.3, 7.2, as well as the latest git master (as of yesterday). These all exhibit this bug. gcc 5.4 does *not* exhibit this bug. The attached reproducer is able to reproduce this issue on a trivial source file by using a gcc plugin that artificially increases the line map's starting location before the preprocessor runs. See README.txt included in the reproduction tarball for instructions on running the reproducer. [mgulick@mgulick2-deb9-64:/local-ssd/mgulick/src/gcc/linemarker_repro] ... $ make /local-ssd/mgulick/src/gcc/git/debug/gcc/xgcc -B /local-ssd/mgulick/src/gcc/git/debug/gcc -E repro.c -o repro.i -fplugin=./location_overflow_plugin.so -fplugin-arg-location_overflow_plugin-value=0x60000000 setting line_table location offset: 1610612736 was (32) /local-ssd/mgulick/src/gcc/git/debug/gcc/xgcc -B /local-ssd/mgulick/src/gcc/git/debug/gcc -c repro.i -o repro.o -Werror In file included from repro_1.h:3, from repro.c:1: repro_2.h:2:16: error: file "repro.h" linemarker ignored due to incorrect nesting [-Werror] ^ repro_2.h:3:16: error: file "repro.c" linemarker ignored due to incorrect nesting [-Werror] #define REPRO_2_H ^ cc1: all warnings being treated as errors Makefile:45: recipe for target 'test_compile' failed make: *** [test_compile] Error 1 [mgulick@mgulick2-deb9-64:/local-ssd/mgulick/src/gcc/linemarker_repro] ... $ cat repro.i # 1 "repro.c" # 1 "<built-in>" # 1 "<command-line>" # 1 "/usr/include/stdc-predef.h" 1 3 4 # 1 "<command-line>" 2 # 1 "repro.c" # 1 "repro.h" 1 # 1 "repro_1.h" 1 # 2 "repro.h" 2 # 3 "repro_1.h" # 1 "repro_2.h" 1 # 2 "repro.h" 2 # 2 "repro.c" 2 The line "# 3 repro_1.h" is incorrect and should not appear.