[PATCH] D52774: [Preprocessor] Fix an assertion failure trigged in clangd #include completion.

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


hokein updated this revision to Diff 167935.
hokein added a comment.

Rescope the patch.


Repository:
  rC Clang

https://reviews.llvm.org/D52774

Files:
  lib/Lex/PPDirectives.cpp


Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1898,21 +1898,24 @@
           }
           return Filename;
         };
-        Filename = CorrectTypoFilename(Filename);
+        StringRef TypoCorrectionName = CorrectTypoFilename(Filename);
         File = LookupFile(
             FilenameLoc,
-            LangOpts.MSVCCompat ? NormalizedPath.c_str() : Filename, isAngled,
+            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() + ">")
+                                     Range, "<" + TypoCorrectionName.str() + ">")
                                : FixItHint::CreateReplacement(
-                                     Range, "\"" + Filename.str() + "\"");
+                                     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;
         }
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52774.167935.patch
Type: text/x-patch
Size: 1652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181002/46796447/attachment.bin>


More information about the cfe-commits mailing list