summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-12-02 01:13:47 +0000
committerChris Lattner <sabre@nondot.org>2007-12-02 01:13:47 +0000
commitf3a59a1fb860c314ea41475b218abf2091ea5dbd (patch)
tree342abcbca505fb943d7c9d14bebd1f319ff1622b /clang
parente6535cfdd29123c5f05d879e2847be098098cdf3 (diff)
downloadbcm5719-llvm-f3a59a1fb860c314ea41475b218abf2091ea5dbd.tar.gz
bcm5719-llvm-f3a59a1fb860c314ea41475b218abf2091ea5dbd.zip
fix a crash when the rewriter would scan off the beginning of the file.
llvm-svn: 44499
Diffstat (limited to 'clang')
-rw-r--r--clang/Driver/RewriteTest.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/clang/Driver/RewriteTest.cpp b/clang/Driver/RewriteTest.cpp
index 2073f7e391f..b199f7151f9 100644
--- a/clang/Driver/RewriteTest.cpp
+++ b/clang/Driver/RewriteTest.cpp
@@ -18,9 +18,10 @@
#include "clang/Basic/SourceManager.h"
#include "clang/Basic/IdentifierTable.h"
#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
-#include "clang/Lex/Lexer.h"
+#include "llvm/Support/MemoryBuffer.h"
#include <sstream>
using namespace clang;
using llvm::utostr;
@@ -32,6 +33,7 @@ namespace {
ASTContext *Context;
SourceManager *SM;
unsigned MainFileID;
+ const char *MainFileStart, *MainFileEnd;
SourceLocation LastIncLoc;
llvm::SmallVector<ObjcImplementationDecl *, 8> ClassImplementation;
llvm::SmallVector<ObjcCategoryImplDecl *, 8> CategoryImplementation;
@@ -58,7 +60,6 @@ namespace {
void Initialize(ASTContext &context, unsigned mainFileID) {
Context = &context;
SM = &Context->SourceMgr;
- MainFileID = mainFileID;
MsgSendFunctionDecl = 0;
MsgSendSuperFunctionDecl = 0;
GetClassFunctionDecl = 0;
@@ -69,6 +70,13 @@ namespace {
CurMethodDecl = 0;
SuperStructDecl = 0;
+ // Get the ID and start/end of the main file.
+ MainFileID = mainFileID;
+ const llvm::MemoryBuffer *MainBuf = SM->getBuffer(MainFileID);
+ MainFileStart = MainBuf->getBufferStart();
+ MainFileEnd = MainBuf->getBufferEnd();
+
+
Rewrite.setSourceMgr(Context->SourceMgr);
// declaring objc_selector outside the parameter list removes a silly
// scope related warning...
@@ -952,7 +960,7 @@ void RewriteTest::RewriteObjcQualifiedInterfaceTypes(
const char *endBuf = SM->getCharacterData(Loc);
const char *startBuf = endBuf;
- while (*startBuf != ';')
+ while (*startBuf != ';' && startBuf != MainFileStart)
startBuf--; // scan backward (from the decl location) for return type.
const char *startRef = 0, *endRef = 0;
if (scanForProtocolRefs(startBuf, endBuf, startRef, endRef)) {
OpenPOWER on IntegriCloud