[clangd] Fix a nullptr-access crash in canonicalRenameDecl.

This commit is contained in:
Haojian Wu
2020-12-03 12:57:41 +01:00
parent 485cd4c52e
commit a59e504a61
2 changed files with 10 additions and 1 deletions

View File

@@ -129,7 +129,8 @@ const NamedDecl *canonicalRenameDecl(const NamedDecl *D) {
// CXXMethodDecl::getInstantiatedFromMemberFunction for the field because
// Clang AST does not store relevant information about the field that is
// instantiated.
const auto *FieldParent = dyn_cast<CXXRecordDecl>(Field->getParent());
const auto *FieldParent =
dyn_cast_or_null<CXXRecordDecl>(Field->getParent());
if (!FieldParent)
return Field->getCanonicalDecl();
FieldParent = FieldParent->getTemplateInstantiationPattern();

View File

@@ -816,6 +816,13 @@ TEST(RenameTest, WithinFileRename) {
[[F^oo]] foo = static_cast<[[F^oo]]>(boo);
}
)cpp",
// ObjC, should not crash.
R"cpp(
@interface ObjC {
char [[da^ta]];
} @end
)cpp",
};
llvm::StringRef NewName = "NewName";
for (llvm::StringRef T : Tests) {
@@ -823,6 +830,7 @@ TEST(RenameTest, WithinFileRename) {
Annotations Code(T);
auto TU = TestTU::withCode(Code.code());
TU.ExtraArgs.push_back("-fno-delayed-template-parsing");
TU.ExtraArgs.push_back("-xobjective-c++");
auto AST = TU.build();
for (const auto &RenamePos : Code.points()) {
auto RenameResult =