r181285 - Have SourceManager::getLocForEndOfFile() point at the "EOF" location of the FileID.
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon May 6 21:29:22 PDT 2013
Author: akirtzidis
Date: Mon May 6 23:29:22 2013
New Revision: 181285
URL: http://llvm.org/viewvc/llvm-project?rev=181285&view=rev
Log:
Have SourceManager::getLocForEndOfFile() point at the "EOF" location of the FileID.
This fixes a crash due to SourceManager::getLocForEndOfFile() returning an off-by-one location
when the the FileID is for an empty file.
rdar://13803893
Added:
cfe/trunk/test/Index/Inputs/empty.h
Modified:
cfe/trunk/include/clang/Basic/SourceManager.h
cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
cfe/trunk/test/Index/file-includes.c
Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=181285&r1=181284&r2=181285&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon May 6 23:29:22 2013
@@ -1005,7 +1005,7 @@ public:
return SourceLocation();
unsigned FileOffset = Entry.getOffset();
- return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID) - 1);
+ return SourceLocation::getFileLoc(FileOffset + getFileIDSize(FID));
}
/// \brief Returns the include location if \p FID is a \#include'd file
Modified: cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp?rev=181285&r1=181284&r2=181285&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp Mon May 6 23:29:22 2013
@@ -464,7 +464,7 @@ bool InclusionRewriter::Process(FileID F
RawLex.LexFromRawLexer(RawToken);
}
OutputContentUpTo(FromFile, NextToWrite,
- SM.getFileOffset(SM.getLocForEndOfFile(FileId)) + 1, EOL, Line,
+ SM.getFileOffset(SM.getLocForEndOfFile(FileId)), EOL, Line,
/*EnsureNewline*/true);
return true;
}
Added: cfe/trunk/test/Index/Inputs/empty.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Inputs/empty.h?rev=181285&view=auto
==============================================================================
(empty)
Modified: cfe/trunk/test/Index/file-includes.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/file-includes.c?rev=181285&r1=181284&r2=181285&view=diff
==============================================================================
--- cfe/trunk/test/Index/file-includes.c (original)
+++ cfe/trunk/test/Index/file-includes.c Mon May 6 23:29:22 2013
@@ -22,3 +22,6 @@ int LocalVar;
// TOP: inclusion directive=targeted-nested1.h ({{.*[/\\]}}test{{[/\\]}}Index{{[/\\]}}targeted-nested1.h) =[5:1 - 5:2]
// TOP: inclusion directive=targeted-fields.h ({{.*[/\\]}}test{{[/\\]}}Index{{[/\\]}}targeted-fields.h) =[16:1 - 16:2]
+
+// rdar://13803893
+// RUN: c-index-test -file-includes-in=%S/Inputs/empty.h %S/Inputs/empty.h
More information about the cfe-commits
mailing list