[PATCH] D64556: [clangd] Fix an assertion crash in "ExtractVariable" tweak
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 11 05:30:37 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL365763: [clangd] Fix an assertion crash in "ExtractVariable" tweak (authored by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D64556?vs=209172&id=209185#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D64556/new/
https://reviews.llvm.org/D64556
Files:
clang-tools-extra/trunk/clangd/Selection.cpp
clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractVariable.cpp
clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
Index: clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractVariable.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractVariable.cpp
+++ clang-tools-extra/trunk/clangd/refactor/tweaks/ExtractVariable.cpp
@@ -81,7 +81,7 @@
// FIXME: Ignore assignment (a = 1) Expr since it is extracted as dummy = a =
static bool isExtractableExpr(const clang::Expr *Expr) {
if (Expr) {
- const Type *ExprType = Expr->getType().getTypePtr();
+ const Type *ExprType = Expr->getType().getTypePtrOrNull();
// FIXME: check if we need to cover any other types
if (ExprType)
return !ExprType->isVoidType();
Index: clang-tools-extra/trunk/clangd/Selection.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/Selection.cpp
+++ clang-tools-extra/trunk/clangd/Selection.cpp
@@ -358,13 +358,10 @@
const Node *SelectionTree::commonAncestor() const {
if (!Root)
return nullptr;
- for (const Node *Ancestor = Root;; Ancestor = Ancestor->Children.front()) {
- if (Ancestor->Selected || Ancestor->Children.size() > 1)
- return Ancestor;
- // The tree only contains ancestors of the interesting nodes.
- assert(!Ancestor->Children.empty() && "bad node in selection tree");
- }
- return nullptr;
+ const Node *Ancestor = Root;
+ while (Ancestor->Children.size() == 1 && !Ancestor->Selected)
+ Ancestor = Ancestor->Children.front();
+ return Ancestor;
}
} // namespace clangd
Index: clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
===================================================================
--- clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/TweakTests.cpp
@@ -313,6 +313,14 @@
while(a < ^3);
}
)cpp");
+ // Should not crash.
+ checkNotAvailable(ID, R"cpp(
+ template<typename T, typename ...Args>
+ struct Test<T, Args...> {
+ Test(const T &v) :val(^) {}
+ T val;
+ };
+ )cpp");
checkNotAvailable(ID, R"cpp(
int xyz(int a = ^1) {
return 1;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64556.209185.patch
Type: text/x-patch
Size: 2123 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190711/58917216/attachment.bin>
More information about the cfe-commits
mailing list