[PATCH] D52721: [Preprocessor] Fix a crash when handling non-alpha include header.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 1 07:40:33 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC343481: [Preprocessor] Fix a crash when handling non-alpha include header. (authored by hokein, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D52721?vs=167737&id=167738#toc
Repository:
rC Clang
https://reviews.llvm.org/D52721
Files:
lib/Lex/PPDirectives.cpp
test/Preprocessor/include-nonalpha-no-crash.c
Index: test/Preprocessor/include-nonalpha-no-crash.c
===================================================================
--- test/Preprocessor/include-nonalpha-no-crash.c
+++ test/Preprocessor/include-nonalpha-no-crash.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify
+
+#include "./" // expected-error {{'./' file not found}}
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1889,13 +1889,16 @@
// 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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52721.167738.patch
Type: text/x-patch
Size: 1427 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181001/e63513b0/attachment.bin>
More information about the cfe-commits
mailing list