r343592 - [Preprocesssor] Filename should fall back to the written name when typo correction fails.

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 07:42:51 PDT 2018


Author: hokein
Date: Tue Oct  2 07:42:51 2018
New Revision: 343592

URL: http://llvm.org/viewvc/llvm-project?rev=343592&view=rev
Log:
[Preprocesssor] Filename should fall back to the written name when typo correction fails.

Summary:
The test is added in  Testcase is at https://reviews.llvm.org/D52775. I tried to add the test to clang's code
completion test, it doesn't reproduce the crash.

Reviewers: sammccall, kristina

Reviewed By: sammccall

Subscribers: kristina, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Differential Revision: https://reviews.llvm.org/D52774

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=343592&r1=343591&r2=343592&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Tue Oct  2 07:42:51 2018
@@ -1898,21 +1898,25 @@ void Preprocessor::HandleIncludeDirectiv
           }
           return Filename;
         };
-        Filename = CorrectTypoFilename(Filename);
+        StringRef TypoCorrectionName = CorrectTypoFilename(Filename);
         File = LookupFile(
             FilenameLoc,
-            LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, isAngled,
-            LookupFrom, LookupFromFile, CurDir,
+            LangOpts.MSVCCompat ? NormalizedPath.c_str() : TypoCorrectionName,
+            isAngled, LookupFrom, LookupFromFile, CurDir,
             Callbacks ? &SearchPath : nullptr,
             Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped);
         if (File) {
           SourceRange Range(FilenameTok.getLocation(), CharEnd);
-          auto Hint = isAngled ? FixItHint::CreateReplacement(
-                                     Range, "<" + Filename.str() + ">")
-                               : FixItHint::CreateReplacement(
-                                     Range, "\"" + Filename.str() + "\"");
+          auto Hint = isAngled
+                          ? FixItHint::CreateReplacement(
+                                Range, "<" + TypoCorrectionName.str() + ">")
+                          : FixItHint::CreateReplacement(
+                                Range, "\"" + TypoCorrectionName.str() + "\"");
           Diag(FilenameTok, diag::err_pp_file_not_found_typo_not_fatal)
-              << OriginalFilename << Filename << Hint;
+              << OriginalFilename << TypoCorrectionName << Hint;
+          // We found the file, so set the Filename to the name after typo
+          // correction.
+          Filename = TypoCorrectionName;
         }
       }
 




More information about the cfe-commits mailing list