[llvm-branch-commits] [clang-tools-extra] a59e504 - [clangd] Fix a nullptr-access crash in canonicalRenameDecl.
Haojian Wu via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Dec 3 04:11:13 PST 2020
Author: Haojian Wu
Date: 2020-12-03T12:59:00+01:00
New Revision: a59e504a61a580e7b7d9af0b0380b573cee21a1c
URL: https://github.com/llvm/llvm-project/commit/a59e504a61a580e7b7d9af0b0380b573cee21a1c
DIFF: https://github.com/llvm/llvm-project/commit/a59e504a61a580e7b7d9af0b0380b573cee21a1c.diff
LOG: [clangd] Fix a nullptr-access crash in canonicalRenameDecl.
Added:
Modified:
clang-tools-extra/clangd/refactor/Rename.cpp
clang-tools-extra/clangd/unittests/RenameTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/refactor/Rename.cpp b/clang-tools-extra/clangd/refactor/Rename.cpp
index 946daaf6d158..0af8a98427c7 100644
--- a/clang-tools-extra/clangd/refactor/Rename.cpp
+++ b/clang-tools-extra/clangd/refactor/Rename.cpp
@@ -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();
diff --git a/clang-tools-extra/clangd/unittests/RenameTests.cpp b/clang-tools-extra/clangd/unittests/RenameTests.cpp
index 2382dba19659..306909892509 100644
--- a/clang-tools-extra/clangd/unittests/RenameTests.cpp
+++ b/clang-tools-extra/clangd/unittests/RenameTests.cpp
@@ -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 =
More information about the llvm-branch-commits
mailing list