summaryrefslogtreecommitdiffstats
path: root/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2018-10-01 14:38:43 +0000
committerHaojian Wu <hokein@google.com>2018-10-01 14:38:43 +0000
commit3c5a31d0525ad2cf81e94ee5c38d45019362a272 (patch)
tree7ea3d224e10867a2aea94b60144dbe1acde068f3 /lib/Lex/PPDirectives.cpp
parent039345a171c5e2d62ff58a6aa42586793f47339f (diff)
[Preprocessor] Fix a crash when handling non-alpha include header.
Summary: the crash is casued by an assertion in StringRef. (llvm::StringRef::front() const: Assertion `!empty()' failed.) Reviewers: sammccall Subscribers: jsji, cfe-commits Differential Revision: https://reviews.llvm.org/D52721 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343481 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PPDirectives.cpp')
-rw-r--r--lib/Lex/PPDirectives.cpp17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 00397e1e1a..2e20a8b9db 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1889,13 +1889,16 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
// characters
StringRef OriginalFilename = Filename;
if (!File) {
- while (!isAlphanumeric(Filename.front())) {
- Filename = Filename.drop_front();
- }
- while (!isAlphanumeric(Filename.back())) {
- Filename = Filename.drop_back();
- }
-
+ // A heuristic to correct a typo file name by removing leading and
+ // trailing non-isAlphanumeric characters.
+ auto CorrectTypoFilename = [](llvm::StringRef Filename) {
+ Filename = Filename.drop_until(isAlphanumeric);
+ while (!Filename.empty() && !isAlphanumeric(Filename.back())) {
+ Filename = Filename.drop_back();
+ }
+ return Filename;
+ };
+ Filename = CorrectTypoFilename(Filename);
File = LookupFile(
FilenameLoc,
LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, isAngled,