https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116047

--- Comment #5 from Ovidiu Panait <ovidiu.panait at windriver dot com> ---
(In reply to Jakub Jelinek from comment #1)
> The compiler represents locations and even location ranges as 32-bit
> integers, so for normally sized sources can encode both line and column and
> range information, but with too many columns or lines gradually loses the
> ranges/column information and later the line information as well.
> Will defer to David for details.

Thanks for the info!

With this particular testcase, the LINE_MAP_MAX_LOCATION (0x70000000) threshold
is not reached, so my understanding is that line information should be correct.
Also, if additional lines are added to "header1.h", the proper line number is
generated in the error message. So this looks like a corner case issue, rather
than the expected behavior.

Dumping linemap info with "-fdump-internal-locations" shows that only
LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES (0x50000000) threshold is exceeded,
which triggers the generation of an empty(?) linemap (ORDINARY MAP 5):
ORDINARY MAP: 4
  location_t interval: 16512 <= loc < 1342178112
  file: header1.h
  starting at line: 1
  column and range bits: 12
  column bits: 7
  range bits: 5
  reason: 0 (LC_ENTER)
  included from location: 12416 (in ordinary map 3)
header1.h:  1|loc:16512|extern int header1_begins;
                       |66666666666666677777777777
                       |55666777888899900011122233
                       |47047036036926925825814814
                       |46802468024680246802468024
<...>
ORDINARY MAP: 5
  location_t interval: 1342178112 <= loc < 1342178112
  file: header1.h
  starting at line: 327678
  column and range bits: 7
  column bits: 7
  range bits: 0
  reason: 2 (LC_RENAME)
  included from location: 12416 (in ordinary map 3)

Having this empty linemap in the linemap list causes the logic in linemap_add()
[1] to generate the wrong line info:
      if (to_file == NULL)
        {
          to_file = ORDINARY_MAP_FILE_NAME (from);
          to_line = SOURCE_LINE (from, from[1].start_location);        
<--------
          sysp = ORDINARY_MAP_IN_SYSTEM_HEADER_P (from);
        }

[1] https://github.com/gcc-mirror/gcc/blob/master/libcpp/line-map.cc#L630


This bug is present in all tested GCC versions and has been affecting our
coverage testing for a long time. We have some workarounds in place, but it
would be nice to finally have a proper solution for this.

Reply via email to