diff options
| author | Haojian Wu <hokein@google.com> | 2018-10-01 14:38:43 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2018-10-01 14:38:43 +0000 |
| commit | 1743ebe369f94289d418dd67b18aec26f2ef10b2 (patch) | |
| tree | cb6ccded505882f1e9f75f203427eabf73906e4c /clang/lib/Lex | |
| parent | 22ae8dabb54778f6819a0874a1f7545c180cfa27 (diff) | |
| download | bcm5719-llvm-1743ebe369f94289d418dd67b18aec26f2ef10b2.tar.gz bcm5719-llvm-1743ebe369f94289d418dd67b18aec26f2ef10b2.zip | |
[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
llvm-svn: 343481
Diffstat (limited to 'clang/lib/Lex')
| -rw-r--r-- | clang/lib/Lex/PPDirectives.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 00397e1e1ac..2e20a8b9dbc 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/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, |

