Need help debugging likely g++ preprocessor bug

Mike Gulick mike.gulick@mathworks.com
Wed Nov 22 23:41:00 GMT 2017


First of all I hope this is the right mailing list.  I did not want to create
a bug report yet as I'm not sure of the cause of the issue and cannot create
a minimal reproduction test case.

I'm seeing an issue where g++ is throwing "linemarker ignored" warnings when
doing a two-stage compile (e.g. using -save-temps, or when compiling with
distcc or ccache).  I can reproduce this issue in GCC 7.2 and 6.3, but not in
5.4.
For example:

 $ /usr/local/gcc-7.2/bin/g++-7.2 \
   -c variants/VariantConditionTable.cpp \
   -o variants/VariantConditionTable.o \
   -save-temps \
   ...
   -pthread -fPIC -std=c++14 -fvisibility=hidden -O0 -g -D_POSIX_C_SOURCE=199506L \
   -fno-omit-frame-pointer -Wall 
  In file included from ../../derived/glnxa64/src/include/cg_ir/fwd/value.hpp:9:0,
                   from ../../derived/glnxa64/src/include/cg_ir/fwd.hpp:7,
                   from variants/VariantConditionTable.cpp:25:
  ../../derived/glnxa64/src/include/cg_ir/fwd/visitor.hpp:8:103: warning: file "../../derived/glnxa64/src/include/cg_ir/../../../../../src/cg_ir/export/include/cg_ir/fwd.hpp" linemarker ignored due to incorrect nesting
   # endif
                                                                                                         ^
  ../../derived/glnxa64/src/include/cg_ir/fwd/visitor.hpp:9:56: warning: file "../../derived/glnxa64/src/include/cg_ir/fwd.hpp" linemarker ignored due to incorrect nesting
   #endif
                                                          ^
  ../../derived/glnxa64/src/include/cg_ir/fwd/visitor.hpp:10:44: warning: file "variants/VariantConditionTable.cpp" linemarker ignored due to incorrect nesting

Performing a single-stage compile works correctly.

This error seems to corrupt the line maps, as warnings will be attributed to the
wrong file/line number, and setting breakpoints based on function names in gdb
will set a breakpoint in a completely different source file and line number.
This makes debugging nearly impossible.

I have been unable to create a minimal use case with any less than 10 or 15
thousand includes (by counting the output of the -H switch), however the issue
is 100% repeatable in our source code.

I have found that I am able to eliminate the warning by modifying one or two 
of the include files.  These include files are a simple list of other #include's.
E.g.

  #pragma once

  #include "a.hpp"
  #include "b.hpp"
  #include "c.hpp"
  ...
  #include "value.hpp"
  #include "visitor.hpp"

This file has a terminating newline, however I have found that by adding an
additional newline at the end of the file, the warnings disappear and the
generated line maps are correct.  Alternatively, adding this additional newline
immediately *before* the last line also seems to fix the issue, however adding
the newline earlier in the file does not.

The contents of "value.hpp" and "visitor.hpp" don't seem to matter.  I have 
commented out the entire contents of these two files save for the '#pragma once'.

Diffing the preprocessor output (the .ii file) from the version generating these
warnings to the version which does not, I get the following diff (I have removed
some whitespace in between the lines):


--- VariantConditionTable_bad.ii 2017-11-22 18:20:39.872201967 -0500
+++ VariantConditionTable.ii  2017-11-22 18:21:32.228549193 -0500
@@ -525631,74 +525631,73 @@
 # 25 "variants/VariantConditionTable.cpp" 2
 # 1 "../../derived/glnxa64/src/include/cg_ir/fwd.hpp" 1
 # 1 "../../derived/glnxa64/src/include/cg_ir/../../../../../src/cg_ir/export/include/cg_ir/fwd.hpp" 1
 # 26 "../../derived/glnxa64/src/include/cg_ir/../../../../../src/cg_ir/export/include/cg_ir/fwd.hpp"
 # 1 "../../derived/glnxa64/src/include/cg_ir/fwd/value.hpp" 1
 # 1 "../../derived/glnxa64/src/include/cg_ir/fwd/../../../../../../src/cg_ir/export/include/cg_ir/fwd/value.hpp" 1
 # 8 "../../derived/glnxa64/src/include/cg_ir/fwd/value.hpp" 2
 # 27 "../../derived/glnxa64/src/include/cg_ir/../../../../../src/cg_ir/export/include/cg_ir/fwd.hpp" 2
-# 9 "../../derived/glnxa64/src/include/cg_ir/fwd/value.hpp"
 # 1 "../../derived/glnxa64/src/include/cg_ir/fwd/visitor.hpp" 1
 # 1 "../../derived/glnxa64/src/include/cg_ir/fwd/../../../../../../src/cg_ir/export/include/cg_ir/fwd/visitor.hpp" 1
 # 8 "../../derived/glnxa64/src/include/cg_ir/fwd/visitor.hpp" 2
-# 27 "../../derived/glnxa64/src/include/cg_ir/../../../../../src/cg_ir/export/include/cg_ir/fwd.hpp" 2
+# 28 "../../derived/glnxa64/src/include/cg_ir/../../../../../src/cg_ir/export/include/cg_ir/fwd.hpp" 2
 # 8 "../../derived/glnxa64/src/include/cg_ir/fwd.hpp" 2
 # 26 "variants/VariantConditionTable.cpp" 2

An additional line marker for 'value.hpp' in being generated in the failing
case, which is corrupting the nesting of the include file stack in the processor
output.

In my attempt to generate a minimal reproduction case, I started by going
through all of the includes and commenting out lines until the warning
disappeared.  I was eventually stopped when I reached a point where there were
several files where adding or deleting a newline *anywhere* in the file
eliminated the problem.

I have tried looking at this in gdb for quite a few days, but I haven't found
any definitive answers.  The one possible clue is that I have noticed that the
source_location numbers in use are close to LINE_MAP_MAX_LOCATION_WITH_COLS
(0x60000000).  E.g. I am seeing source locations in the debugger of 1610043911
(0x5FF75207).  In other examples, I am seeing source locations just over this
limit.

I would greatly appreciate suggestions for debugging this issue further.  I have
been looking at it for over a week and am hitting a bit of a wall.

Thanks in advance!

-Mike



More information about the Gcc-help mailing list