]> granicus.if.org Git - clang/commitdiff
Have SourceManager::getLocForEndOfFile() point at the "EOF" location of the FileID.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 7 May 2013 04:29:22 +0000 (04:29 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 7 May 2013 04:29:22 +0000 (04:29 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181285 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h
lib/Rewrite/Frontend/InclusionRewriter.cpp
test/Index/Inputs/empty.h [new file with mode: 0644]
test/Index/file-includes.c

index f82b196929a39f65c85305195b20d109d011206c..eccbf1ede7f181cdefb8aad7908cb10c3bc7abbb 100644 (file)
@@ -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
index 878be84224ae4d23efb6715e3ce4e38b680784bb..9e4bb3c89bcff94c74bbca94fc01a0ef09261ede 100644 (file)
@@ -464,7 +464,7 @@ bool InclusionRewriter::Process(FileID FileId,
     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;
 }
diff --git a/test/Index/Inputs/empty.h b/test/Index/Inputs/empty.h
new file mode 100644 (file)
index 0000000..e69de29
index 2dfced0c0c4f1973587e0be787dc4f3a5f255f82..ac3d568dc53d1a639249099444c0959ad0fd3c59 100644 (file)
@@ -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