[clang-tools-extra] cca10be - [clangd] Fix a crash bug in AddUsing tweak around template handling.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 8 04:59:55 PDT 2020
Author: Adam Czachorowski
Date: 2020-04-08T13:59:47+02:00
New Revision: cca10be3f60dd30055acc70d117649f889da779d
URL: https://github.com/llvm/llvm-project/commit/cca10be3f60dd30055acc70d117649f889da779d
DIFF: https://github.com/llvm/llvm-project/commit/cca10be3f60dd30055acc70d117649f889da779d.diff
LOG: [clangd] Fix a crash bug in AddUsing tweak around template handling.
Summary:
The crash happened on cases like:
template<typename TT> using one = two::three<T^T>;
because we tried to call getName() on getBaseTypeIdentifier(), which can
be nullptr.
Ideally we would support this use case as well, but for now not crashing
will do.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77656
Added:
Modified:
clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
clang-tools-extra/clangd/unittests/TweakTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
index 411c685e2b7d..f2ef235c43f7 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -206,9 +206,11 @@ bool AddUsing::prepare(const Selection &Inputs) {
Name = D->getDecl()->getName();
} else if (auto *T = Node->ASTNode.get<TypeLoc>()) {
if (auto E = T->getAs<ElaboratedTypeLoc>()) {
- QualifierToRemove = E.getQualifierLoc();
- Name =
- E.getType().getUnqualifiedType().getBaseTypeIdentifier()->getName();
+ if (auto *BaseTypeIdentifier =
+ E.getType().getUnqualifiedType().getBaseTypeIdentifier()) {
+ Name = BaseTypeIdentifier->getName();
+ QualifierToRemove = E.getQualifierLoc();
+ }
}
}
diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index 979ee44f4474..b93cca23e6b6 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -2436,6 +2436,7 @@ TEST_F(AddUsingTest, Prepare) {
#define NS(name) one::two::name
namespace one {
void oo() {}
+template<typename TT> class tt {};
namespace two {
enum ee {};
void ff() {}
@@ -2458,6 +2459,10 @@ class cc {
EXPECT_UNAVAILABLE(Header +
"void fun() { o^n^e^:^:^t^w^o^:^:^c^c^:^:^s^t inst; }");
EXPECT_UNAVAILABLE(Header + "void fun() { N^S(c^c) inst; }");
+ // This used to crash. Ideally we would support this case, but for now we just
+ // test that we don't crash.
+ EXPECT_UNAVAILABLE(Header +
+ "template<typename TT> using foo = one::tt<T^T>;");
}
TEST_F(AddUsingTest, Apply) {
More information about the cfe-commits
mailing list