diff mbox

[libcpp] Do not decrease highest_location if the included file has be included twice.

Message ID CAO2gOZUDxMdOan2ffPX+Wj1QMbu7FMJLORb4qhzw1zGLTj4MjA@mail.gmail.com
State New
Headers show

Commit Message

Dehao Chen June 3, 2013, 5:08 p.m. UTC
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
diff mbox

Patch

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;