From: Haojian Wu Date: Tue, 2 Oct 2018 14:42:51 +0000 (+0000) Subject: [Preprocesssor] Filename should fall back to the written name when typo correction... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4b113a837e49832df9559d5d032d4cc3903d69a9;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343592 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index ceddada9eb..af922c0698 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -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; } }