Hi, Dodji,

Thanks for looking into this.

The reason a test is missing is that it would need a super large
source file to reproduce the problem. However, if you apply the
attached patch, you can reproduce the problem with attached testcase:

g++ a.cpp -g -S -c -o a.s

in a.s, the linenos are off-by-one.

The root cause is that highest_location-- should not happen when the
header file is not gonna be read. In should_stack file, there is
following check:

  /* Skip if the file had a header guard and the macro is defined.
     PCH relies on this appearing before the PCH handler below.  */
  if (file->cmacro && file->cmacro->type == NT_MACRO)
    return false;

Thus we should add it back to _cpp_stack_include too.

The problem was hidden when column number is used because
highest_location is updated in linemap_position_for_column. However,
when linemap are too large, it disables columns and do not update the
highest_location.

Dehao
Index: libcpp/line-map.c
===================================================================
--- libcpp/line-map.c   (revision 199570)
+++ libcpp/line-map.c   (working copy)
@@ -536,7 +536,7 @@ linemap_line_start (struct line_maps *set, linenum
   if (add_map)
     {
       int column_bits;
-      if (max_column_hint > 100000 || highest > 0x60000000)
+      if (1 || max_column_hint > 100000 || highest > 0x60000000)
        {
          /* If the column number is ridiculous or we've allocated a huge
             number of source_locations, give up on column numbers. */
@@ -598,7 +598,7 @@ linemap_position_for_column (struct line_maps *set
 
   if (to_column >= set->max_column_hint)
     {
-      if (r >= 0xC000000 || to_column > 100000)
+      if (1 || r >= 0xC000000 || to_column > 100000)
        {
          /* Running low on source_locations - disable column numbers.  */
          return r;
#include "inc_1.h"
#include "inc_2.h"

int main() {
  foo();
  boo();
  return 0;
}
#ifndef _INC_1_H_
#define _INC_1_H_
#include "inc_2.h"
void foo (void);
#endif
#ifndef _INC_2_H_
#define _INC_2_H_
void boo (void);
#endif

Reply via email to