]> granicus.if.org Git - clang/commitdiff
[Preprocesssor] Filename should fall back to the written name when typo correction...
authorHaojian Wu <hokein@google.com>
Tue, 2 Oct 2018 14:42:51 +0000 (14:42 +0000)
committerHaojian Wu <hokein@google.com>
Tue, 2 Oct 2018 14:42:51 +0000 (14:42 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343592 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp

index ceddada9eb8759ba41930b033424bdc4f4218596..af922c06981ae8b61d1e26b600e45c68c5c04d02 100644 (file)
@@ -1898,21 +1898,25 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
           }
           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;
         }
       }