[PATCH] D52778: [Preprocessor] Hide include typo correction behind SpellChecking.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 2 06:07:34 PDT 2018


hokein created this revision.
hokein added a reviewer: sammccall.

Similar to Sema typo correction, the Preprocessor typo correction should
also be hidden behind the SpellChecking flag.


Repository:
  rC Clang

https://reviews.llvm.org/D52778

Files:
  lib/Lex/PPDirectives.cpp


Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1888,31 +1888,33 @@
       // Check for likely typos due to leading or trailing non-isAlphanumeric
       // characters
       StringRef OriginalFilename = Filename;
-      if (!File) {
-        // 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();
+      if (LangOpts.SpellChecking) {
+        if (!File) {
+          // 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,
+              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() + "\"");
+            Diag(FilenameTok, diag::err_pp_file_not_found_typo_not_fatal)
+                << OriginalFilename << Filename << Hint;
           }
-          return Filename;
-        };
-        Filename = CorrectTypoFilename(Filename);
-        File = LookupFile(
-            FilenameLoc,
-            LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, 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() + "\"");
-          Diag(FilenameTok, diag::err_pp_file_not_found_typo_not_fatal)
-              << OriginalFilename << Filename << Hint;
         }
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52778.167931.patch
Type: text/x-patch
Size: 3043 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181002/952fa109/attachment.bin>


More information about the cfe-commits mailing list