mirror of
https://github.com/intel/llvm.git
synced 2026-01-26 03:56:16 +08:00
[clangd] Fix a nullptr-access crash in canonicalRenameDecl.
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user