forked from OSchip/llvm-project
fix sometimes incorrect line numbers in -frewrite-includes mode (pr#14795)
Every #include is surrounded by #if 0 in order to comment it out, which adds lines. That is fixed up right after, but that all can be inside #if part that is not processed, so fix up also after every end of a conditional part. llvm-svn: 186763
This commit is contained in:
parent
a3d5304ec0
commit
4c22f6a695
|
@ -365,7 +365,7 @@ bool InclusionRewriter::Process(FileID FileId,
|
||||||
RawLex.LexFromRawLexer(RawToken);
|
RawLex.LexFromRawLexer(RawToken);
|
||||||
if (RawToken.is(tok::raw_identifier))
|
if (RawToken.is(tok::raw_identifier))
|
||||||
PP.LookUpIdentifierInfo(RawToken);
|
PP.LookUpIdentifierInfo(RawToken);
|
||||||
if (RawToken.is(tok::identifier) || RawToken.is(tok::kw_if)) {
|
if (RawToken.getIdentifierInfo() != NULL) {
|
||||||
switch (RawToken.getIdentifierInfo()->getPPKeywordID()) {
|
switch (RawToken.getIdentifierInfo()->getPPKeywordID()) {
|
||||||
case tok::pp_include:
|
case tok::pp_include:
|
||||||
case tok::pp_include_next:
|
case tok::pp_include_next:
|
||||||
|
@ -412,7 +412,9 @@ bool InclusionRewriter::Process(FileID FileId,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case tok::pp_if:
|
case tok::pp_if:
|
||||||
case tok::pp_elif:
|
case tok::pp_elif: {
|
||||||
|
bool elif = (RawToken.getIdentifierInfo()->getPPKeywordID() ==
|
||||||
|
tok::pp_elif);
|
||||||
// Rewrite special builtin macros to avoid pulling in host details.
|
// Rewrite special builtin macros to avoid pulling in host details.
|
||||||
do {
|
do {
|
||||||
// Walk over the directive.
|
// Walk over the directive.
|
||||||
|
@ -453,8 +455,33 @@ bool InclusionRewriter::Process(FileID FileId,
|
||||||
OS << "*/";
|
OS << "*/";
|
||||||
}
|
}
|
||||||
} while (RawToken.isNot(tok::eod));
|
} while (RawToken.isNot(tok::eod));
|
||||||
|
if (elif) {
|
||||||
|
OutputContentUpTo(FromFile, NextToWrite,
|
||||||
|
SM.getFileOffset(RawToken.getLocation()) +
|
||||||
|
RawToken.getLength(),
|
||||||
|
EOL, Line, /*EnsureNewLine*/ true);
|
||||||
|
WriteLineInfo(FileName, Line, FileType, EOL);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
case tok::pp_endif:
|
||||||
|
case tok::pp_else: {
|
||||||
|
// We surround every #include by #if 0 to comment it out, but that
|
||||||
|
// changes line numbers. These are fixed up right after that, but
|
||||||
|
// the whole #include could be inside a preprocessor conditional
|
||||||
|
// that is not processed. So it is necessary to fix the line
|
||||||
|
// numbers one the next line after each #else/#endif as well.
|
||||||
|
RawLex.SetKeepWhitespaceMode(true);
|
||||||
|
do {
|
||||||
|
RawLex.LexFromRawLexer(RawToken);
|
||||||
|
} while (RawToken.isNot(tok::eod) && RawToken.isNot(tok::eof));
|
||||||
|
OutputContentUpTo(
|
||||||
|
FromFile, NextToWrite,
|
||||||
|
SM.getFileOffset(RawToken.getLocation()) + RawToken.getLength(),
|
||||||
|
EOL, Line, /*EnsureNewLine*/ true);
|
||||||
|
WriteLineInfo(FileName, Line, FileType, EOL);
|
||||||
|
RawLex.SetKeepWhitespaceMode(false);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ A(1,2)
|
||||||
#else
|
#else
|
||||||
#include "rewrite-includes4.h"
|
#include "rewrite-includes4.h"
|
||||||
#endif
|
#endif
|
||||||
|
// indented
|
||||||
#/**/include /**/ "rewrite-includes5.h" /**/ \
|
#/**/include /**/ "rewrite-includes5.h" /**/ \
|
||||||
|
|
||||||
#include "rewrite-includes6.h" // comment
|
#include "rewrite-includes6.h" // comment
|
||||||
|
@ -48,18 +49,21 @@ A(1,2)
|
||||||
// CHECK-NEXT: {{^}}included_line3{{$}}
|
// CHECK-NEXT: {{^}}included_line3{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 10 "{{.*}}rewrite-includes.c" 2{{$}}
|
// CHECK-NEXT: {{^}}# 10 "{{.*}}rewrite-includes.c" 2{{$}}
|
||||||
// CHECK-NEXT: {{^}}#else{{$}}
|
// CHECK-NEXT: {{^}}#else{{$}}
|
||||||
|
// CHECK-NEXT: {{^}}# 11 "{{.*}}rewrite-includes.c"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#include "rewrite-includes4.h"{{$}}
|
// CHECK-NEXT: {{^}}#include "rewrite-includes4.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 12 "{{.*}}rewrite-includes.c"{{$}}
|
// CHECK-NEXT: {{^}}# 12 "{{.*}}rewrite-includes.c"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif{{$}}
|
// CHECK-NEXT: {{^}}#endif{{$}}
|
||||||
|
// CHECK-NEXT: {{^}}# 13 "{{.*}}rewrite-includes.c"{{$}}
|
||||||
|
// CHECK-NEXT: {{^}} // indented{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#/**/include /**/ "rewrite-includes5.h" /**/ {{\\}}{{$}}
|
// CHECK-NEXT: {{^}}#/**/include /**/ "rewrite-includes5.h" /**/ {{\\}}{{$}}
|
||||||
// CHECK-NEXT: {{^}} {{$}}
|
// CHECK-NEXT: {{^}} {{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs[/\\]}}rewrite-includes5.h" 1{{$}}
|
// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs[/\\]}}rewrite-includes5.h" 1{{$}}
|
||||||
// CHECK-NEXT: {{^}}included_line5{{$}}
|
// CHECK-NEXT: {{^}}included_line5{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 15 "{{.*}}rewrite-includes.c" 2{{$}}
|
// CHECK-NEXT: {{^}}# 16 "{{.*}}rewrite-includes.c" 2{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#include "rewrite-includes6.h" // comment{{$}}
|
// CHECK-NEXT: {{^}}#include "rewrite-includes6.h" // comment{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
|
@ -69,13 +73,13 @@ A(1,2)
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 2 "{{.*[/\\]Inputs[/\\]}}rewrite-includes6.h"{{$}}
|
// CHECK-NEXT: {{^}}# 2 "{{.*[/\\]Inputs[/\\]}}rewrite-includes6.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}included_line6{{$}}
|
// CHECK-NEXT: {{^}}included_line6{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 16 "{{.*}}rewrite-includes.c" 2{{$}}
|
// CHECK-NEXT: {{^}}# 17 "{{.*}}rewrite-includes.c" 2{{$}}
|
||||||
// CHECK-NEXT: {{^}} {{$}}
|
// CHECK-NEXT: {{^}} {{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#include "rewrite-includes6.h" /* comment{{$}}
|
// CHECK-NEXT: {{^}}#include "rewrite-includes6.h" /* comment{{$}}
|
||||||
// CHECK-NEXT: {{^}} continues */{{$}}
|
// CHECK-NEXT: {{^}} continues */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 19 "{{.*}}rewrite-includes.c"{{$}}
|
// CHECK-NEXT: {{^}}# 20 "{{.*}}rewrite-includes.c"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#include "rewrite-includes7.h"{{$}}
|
// CHECK-NEXT: {{^}}#include "rewrite-includes7.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
|
@ -84,21 +88,25 @@ A(1,2)
|
||||||
// CHECK-NEXT: {{^}}#define REWRITE_INCLUDES_7{{$}}
|
// CHECK-NEXT: {{^}}#define REWRITE_INCLUDES_7{{$}}
|
||||||
// CHECK-NEXT: {{^}}included_line7{{$}}
|
// CHECK-NEXT: {{^}}included_line7{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif{{$}}
|
// CHECK-NEXT: {{^}}#endif{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 20 "{{.*}}rewrite-includes.c" 2{{$}}
|
// CHECK-NEXT: {{^}}# 5 "{{.*[/\\]Inputs[/\\]}}rewrite-includes7.h"{{$}}
|
||||||
|
// CHECK-NEXT: {{^}}# 21 "{{.*}}rewrite-includes.c" 2{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#include "rewrite-includes7.h"{{$}}
|
// CHECK-NEXT: {{^}}#include "rewrite-includes7.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 21 "{{.*}}rewrite-includes.c"{{$}}
|
// CHECK-NEXT: {{^}}# 22 "{{.*}}rewrite-includes.c"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}#include "rewrite-includes8.h"{{$}}
|
// CHECK-NEXT: {{^}}#include "rewrite-includes8.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs[/\\]}}rewrite-includes8.h" 1{{$}}
|
// CHECK-NEXT: {{^}}# 1 "{{.*[/\\]Inputs[/\\]}}rewrite-includes8.h" 1{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if (1)/*__has_include_next(<rewrite-includes8.h>)*/{{$}}
|
// CHECK-NEXT: {{^}}#if (1)/*__has_include_next(<rewrite-includes8.h>)*/{{$}}
|
||||||
// CHECK-NEXT: {{^}}#elif (0)/*__has_include(<rewrite-includes8.hfail>)*/{{$}}
|
// CHECK-NEXT: {{^}}#elif (0)/*__has_include(<rewrite-includes8.hfail>)*/{{$}}
|
||||||
|
// CHECK-NEXT: {{^}}# 3 "{{.*[/\\]Inputs[/\\]}}rewrite-includes8.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif{{$}}
|
// CHECK-NEXT: {{^}}#endif{{$}}
|
||||||
|
// CHECK-NEXT: {{^}}# 4 "{{.*[/\\]Inputs[/\\]}}rewrite-includes8.h"{{$}}
|
||||||
// CHECK-NEXT: {{^}}#if !(1)/*__has_include("rewrite-includes8.h")*/{{$}}
|
// CHECK-NEXT: {{^}}#if !(1)/*__has_include("rewrite-includes8.h")*/{{$}}
|
||||||
// CHECK-NEXT: {{^}}#endif{{$}}
|
// CHECK-NEXT: {{^}}#endif{{$}}
|
||||||
// CHECK-NEXT: {{^}}# 22 "{{.*}}rewrite-includes.c" 2{{$}}
|
// CHECK-NEXT: {{^}}# 6 "{{.*[/\\]Inputs[/\\]}}rewrite-includes8.h"{{$}}
|
||||||
|
// CHECK-NEXT: {{^}}# 23 "{{.*}}rewrite-includes.c" 2{{$}}
|
||||||
// CHECK-NEXT: {{^}}// ENDCOMPARE{{$}}
|
// CHECK-NEXT: {{^}}// ENDCOMPARE{{$}}
|
||||||
|
|
||||||
// CHECKNL: {{^}}// STARTCOMPARE{{$}}
|
// CHECKNL: {{^}}// STARTCOMPARE{{$}}
|
||||||
|
@ -126,6 +134,7 @@ A(1,2)
|
||||||
// CHECKNL-NEXT: {{^}}#include "rewrite-includes4.h"{{$}}
|
// CHECKNL-NEXT: {{^}}#include "rewrite-includes4.h"{{$}}
|
||||||
// CHECKNL-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
// CHECKNL-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECKNL-NEXT: {{^}}#endif{{$}}
|
// CHECKNL-NEXT: {{^}}#endif{{$}}
|
||||||
|
// CHECKNL-NEXT: {{^}} // indented{{$}}
|
||||||
// CHECKNL-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
// CHECKNL-NEXT: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
|
||||||
// CHECKNL-NEXT: {{^}}#/**/include /**/ "rewrite-includes5.h" /**/ {{\\}}{{$}}
|
// CHECKNL-NEXT: {{^}}#/**/include /**/ "rewrite-includes5.h" /**/ {{\\}}{{$}}
|
||||||
// CHECKNL-NEXT: {{^}} {{$}}
|
// CHECKNL-NEXT: {{^}} {{$}}
|
||||||
|
|
Loading…
Reference in New Issue