[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:30:20 PDT 2018
hokein updated this revision to Diff 167737.
hokein marked 3 inline comments as done.
hokein added a comment.
Address review comments.
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
===================================================================
--- /dev/null
+++ 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.167737.patch
Type: text/x-patch
Size: 1391 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181001/93f0d1aa/attachment-0001.bin>
More information about the cfe-commits
mailing list