summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/PrintPreprocessedOutput.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-11-12 07:15:47 +0000
committerDouglas Gregor <dgregor@apple.com>2010-11-12 07:15:47 +0000
commit453b012513e67aa99b3d4c5f7712231012efeca3 (patch)
treef50a2385ab797dfb12f0745b98f0fe697332b5c2 /clang/lib/Frontend/PrintPreprocessedOutput.cpp
parentea18d8ec2d4c153511d38f85e65c78c3e637d3c6 (diff)
downloadbcm5719-llvm-453b012513e67aa99b3d4c5f7712231012efeca3.tar.gz
bcm5719-llvm-453b012513e67aa99b3d4c5f7712231012efeca3.zip
Make sure to always check the result of
SourceManager::getPresumedLoc(), so that we don't try to make use of an invalid presumed location. Doing so can cause crashes. llvm-svn: 118885
Diffstat (limited to 'clang/lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 6019b308338..429999cd5e3 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -131,7 +131,10 @@ public:
bool HandleFirstTokOnLine(Token &Tok);
bool MoveToLine(SourceLocation Loc) {
- return MoveToLine(SM.getPresumedLoc(Loc).getLine());
+ PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+ if (PLoc.isInvalid())
+ return false;
+ return MoveToLine(PLoc.getLine());
}
bool MoveToLine(unsigned LineNo);
@@ -238,10 +241,13 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
SourceManager &SourceMgr = SM;
PresumedLoc UserLoc = SourceMgr.getPresumedLoc(Loc);
+ if (UserLoc.isInvalid())
+ return;
+
unsigned NewLine = UserLoc.getLine();
if (Reason == PPCallbacks::EnterFile) {
- SourceLocation IncludeLoc = SourceMgr.getPresumedLoc(Loc).getIncludeLoc();
+ SourceLocation IncludeLoc = UserLoc.getIncludeLoc();
if (IncludeLoc.isValid())
MoveToLine(IncludeLoc);
} else if (Reason == PPCallbacks::SystemHeaderPragma) {
@@ -593,10 +599,18 @@ void clang::DoPrintPreprocessedInput(Preprocessor &PP, llvm::raw_ostream *OS,
// start.
const SourceManager &SourceMgr = PP.getSourceManager();
Token Tok;
- do PP.Lex(Tok);
- while (Tok.isNot(tok::eof) && Tok.getLocation().isFileID() &&
- !strcmp(SourceMgr.getPresumedLoc(Tok.getLocation()).getFilename(),
- "<built-in>"));
+ do {
+ PP.Lex(Tok);
+ if (Tok.is(tok::eof) || !Tok.getLocation().isFileID())
+ break;
+
+ PresumedLoc PLoc = SourceMgr.getPresumedLoc(Tok.getLocation());
+ if (PLoc.isInvalid())
+ break;
+
+ if (strcmp(PLoc.getFilename(), "<built-in>"))
+ break;
+ } while (true);
// Read all the preprocessed tokens, printing them out to the stream.
PrintPreprocessedTokens(PP, Tok, Callbacks, *OS);
OpenPOWER on IntegriCloud