summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2018-10-02 14:42:51 +0000
committerHaojian Wu <hokein@google.com>2018-10-02 14:42:51 +0000
commit714e971540dbb3e2cb4613a82ae75c101c85e48c (patch)
tree0dad9e0e2bdb1a802f3a6b04beb05ca4574d6e7f
parentdea577191cf608d57b5bf14e67a517539433a5d0 (diff)
downloadbcm5719-llvm-714e971540dbb3e2cb4613a82ae75c101c85e48c.tar.gz
bcm5719-llvm-714e971540dbb3e2cb4613a82ae75c101c85e48c.zip
[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 llvm-svn: 343592
-rw-r--r--clang/lib/Lex/PPDirectives.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index ceddada9eb8..af922c06981 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/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;
}
}
OpenPOWER on IntegriCloud