[clang-tools-extra] r341322 - [clangd] Avoid crashes in override completions
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 3 08:25:27 PDT 2018
Author: ibiryukov
Date: Mon Sep 3 08:25:27 2018
New Revision: 341322
URL: http://llvm.org/viewvc/llvm-project?rev=341322&view=rev
Log:
[clangd] Avoid crashes in override completions
Summary: NamedDecl::getName cannot be called on non-identifier names.
Reviewers: kadircet, ioeric, hokein, sammccall
Reviewed By: ioeric
Subscribers: MaskRay, jkorous, arphaman, cfe-commits
Differential Revision: https://reviews.llvm.org/D51598
Modified:
clang-tools-extra/trunk/clangd/CodeComplete.cpp
clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
Modified: clang-tools-extra/trunk/clangd/CodeComplete.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/CodeComplete.cpp?rev=341322&r1=341321&r2=341322&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/CodeComplete.cpp (original)
+++ clang-tools-extra/trunk/clangd/CodeComplete.cpp Mon Sep 3 08:25:27 2018
@@ -210,7 +210,7 @@ getNonOverridenMethodCompletionResults(c
// These are stored by name to make querying fast in the later step.
llvm::StringMap<std::vector<FunctionDecl *>> Overrides;
for (auto *Method : CR->methods()) {
- if (!Method->isVirtual())
+ if (!Method->isVirtual() || !Method->getIdentifier())
continue;
Overrides[Method->getName()].push_back(Method);
}
@@ -221,14 +221,14 @@ getNonOverridenMethodCompletionResults(c
if (!BR)
continue;
for (auto *Method : BR->methods()) {
- if (!Method->isVirtual())
+ if (!Method->isVirtual() || !Method->getIdentifier())
continue;
const auto it = Overrides.find(Method->getName());
bool IsOverriden = false;
if (it != Overrides.end()) {
for (auto *MD : it->second) {
// If the method in current body is not an overload of this virtual
- // function, that it overrides this one.
+ // function, then it overrides this one.
if (!S->IsOverload(MD, Method, false)) {
IsOverriden = true;
break;
Modified: clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp?rev=341322&r1=341321&r2=341322&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/CodeCompleteTests.cpp Mon Sep 3 08:25:27 2018
@@ -1765,6 +1765,21 @@ TEST(CompletionTest, SuggestOverrides) {
Not(Contains(Labeled("void vfunc(bool param) override")))));
}
+TEST(CompletionTest, OverridesNonIdentName) {
+ // Check the completions call does not crash.
+ completions(R"cpp(
+ struct Base {
+ virtual ~Base() = 0;
+ virtual operator int() = 0;
+ virtual Base& operator+(Base&) = 0;
+ };
+
+ struct Derived : Base {
+ ^
+ };
+ )cpp");
+}
+
TEST(SpeculateCompletionFilter, Filters) {
Annotations F(R"cpp($bof^
$bol^
More information about the cfe-commits
mailing list