diff options
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 17 | ||||
-rw-r--r-- | test/Preprocessor/include-nonalpha-no-crash.c | 3 |
2 files changed, 13 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, diff --git a/test/Preprocessor/include-nonalpha-no-crash.c b/test/Preprocessor/include-nonalpha-no-crash.c new file mode 100644 index 0000000000..31c1348f02 --- /dev/null +++ b/test/Preprocessor/include-nonalpha-no-crash.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 %s -verify + +#include "./" // expected-error {{'./' file not found}} |