r179143 - [frontend] -frewrite-includes: if there was no inclusion, don't add lineinfo that indicates return from another file.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Apr 9 18:53:37 PDT 2013
Author: akirtzidis
Date: Tue Apr 9 20:53:37 2013
New Revision: 179143
URL: http://llvm.org/viewvc/llvm-project?rev=179143&view=rev
Log:
[frontend] -frewrite-includes: if there was no inclusion, don't add lineinfo that indicates return from another file.
Modified:
cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
cfe/trunk/test/Frontend/rewrite-includes-missing.c
Modified: cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp?rev=179143&r1=179142&r2=179143&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp Tue Apr 9 20:53:37 2013
@@ -253,7 +253,7 @@ bool InclusionRewriter::Process(FileID F
bool Invalid;
const MemoryBuffer &FromFile = *SM.getBuffer(FileId, &Invalid);
if (Invalid) // invalid inclusion
- return true;
+ return false;
const char *FileName = FromFile.getBufferIdentifier();
Lexer RawLex(FileId, &FromFile, PP.getSourceManager(), PP.getLangOpts());
RawLex.SetCommentRetentionState(false);
@@ -264,7 +264,7 @@ bool InclusionRewriter::Process(FileID F
WriteLineInfo(FileName, 1, FileType, EOL, " 1");
if (SM.getFileIDSize(FileId) == 0)
- return true;
+ return false;
// The next byte to be copied from the source file
unsigned NextToWrite = 0;
@@ -292,12 +292,17 @@ bool InclusionRewriter::Process(FileID F
if (const FileChange *Change = FindFileChangeLocation(
HashToken.getLocation())) {
// now include and recursively process the file
- if (Process(Change->Id, Change->FileType))
+ if (Process(Change->Id, Change->FileType)) {
// and set lineinfo back to this file, if the nested one was
// actually included
// `2' indicates returning to a file (after having included
// another file.
WriteLineInfo(FileName, Line, FileType, EOL, " 2");
+ } else {
+ // fix up lineinfo (since commented out directive changed line
+ // numbers).
+ WriteLineInfo(FileName, Line, FileType, EOL);
+ }
} else
// fix up lineinfo (since commented out directive changed line
// numbers) for inclusions that were skipped due to header guards
Modified: cfe/trunk/test/Frontend/rewrite-includes-missing.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-missing.c?rev=179143&r1=179142&r2=179143&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/rewrite-includes-missing.c (original)
+++ cfe/trunk/test/Frontend/rewrite-includes-missing.c Tue Apr 9 20:53:37 2013
@@ -4,4 +4,4 @@
// CHECK: {{^}}#if 0 /* expanded by -frewrite-includes */{{$}}
// CHECK-NEXT: {{^}}#include "foobar.h"
// CHECK-NEXT: {{^}}#endif /* expanded by -frewrite-includes */{{$}}
-// CHECK-NEXT: {{^}}# 4 "{{.*}}rewrite-includes-missing.c" 2{{$}}
+// CHECK-NEXT: {{^}}# 4 "{{.*}}rewrite-includes-missing.c"{{$}}
More information about the cfe-commits
mailing list