[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
This commit is contained in:
parent
22ae8dabb5
commit
1743ebe369
@ -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,
|
||||
|
||||
3
clang/test/Preprocessor/include-nonalpha-no-crash.c
Normal file
3
clang/test/Preprocessor/include-nonalpha-no-crash.c
Normal file
@ -0,0 +1,3 @@
|
||||
// RUN: %clang_cc1 %s -verify
|
||||
|
||||
#include "./" // expected-error {{'./' file not found}}
|
||||
Loading…
x
Reference in New Issue
Block a user