summaryrefslogtreecommitdiff
path: root/clang/lib/Lex/Preprocessor.cpp
diff options
context:
space:
mode:
authorDiogo Sampaio <diogo.sampaio@arm.com>2020-01-24 23:56:12 +0000
committerDiogo Sampaio <diogo.sampaio@arm.com>2020-01-24 23:56:47 +0000
commitbce360b7048cc6306c9d04faf27b71eec8762041 (patch)
treeef0a2a6952190c395bb7be4bfa70fa18a3ac64bd /clang/lib/Lex/Preprocessor.cpp
parentec62bf2fd3284c9a525011b191c4960fce01dca7 (diff)
Detect source location overflow due includes
Summary: As discussed in http://lists.llvm.org/pipermail/cfe-dev/2019-October/063459.html the overflow of the souce locations (limited to 2^31 chars) can generate all sorts of weird things (bogus warnings, hangs, crashes, miscompilation and correct compilation). In debug mode this assert would fail. So it might be a good start, as in PR42301, to detect the failure and exit with a proper error message. Reviewers: rsmith, thakis, miyuki Reviewed By: miyuki Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70183
Diffstat (limited to 'clang/lib/Lex/Preprocessor.cpp')
-rw-r--r--clang/lib/Lex/Preprocessor.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 0e9be3923630..a18dc4af4226 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -906,6 +906,9 @@ void Preprocessor::Lex(Token &Result) {
}
} while (!ReturnedToken);
+ if (Result.is(tok::unknown) && TheModuleLoader.HadFatalFailure)
+ return;
+
if (Result.is(tok::code_completion) && Result.getIdentifierInfo()) {
// Remember the identifier before code completion token.
setCodeCompletionIdentifierInfo(Result.getIdentifierInfo());
@@ -1200,6 +1203,13 @@ bool Preprocessor::LexAfterModuleImport(Token &Result) {
Suffix[0].setAnnotationValue(Action.ModuleForHeader);
// FIXME: Call the moduleImport callback?
break;
+ case ImportAction::Failure:
+ assert(TheModuleLoader.HadFatalFailure &&
+ "This should be an early exit only to a fatal error");
+ Result.setKind(tok::eof);
+ CurLexer->cutOffLexing();
+ EnterTokens(Suffix);
+ return true;
}
EnterTokens(Suffix);