This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, libcpp] Do not decrease highest_location if the included file has be included twice.


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

Attachment: patch.txt
Description: Text document

#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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]