hokein created this revision. hokein added reviewers: sammccall, SureYeaah. Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ilya-biryukov. Herald added a project: clang.
GetTypePtr requires that the type should not be null, otherwise we hit an assertion, we should use getTypePtrOrNull instead. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D64556 Files: clang-tools-extra/clangd/Selection.cpp clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp clang-tools-extra/clangd/unittests/TweakTests.cpp Index: clang-tools-extra/clangd/unittests/TweakTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTests.cpp +++ clang-tools-extra/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; Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp =================================================================== --- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ clang-tools-extra/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/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -359,12 +359,13 @@ if (!Root) return nullptr; for (const Node *Ancestor = Root;; Ancestor = Ancestor->Children.front()) { + assert(Ancestor && "Ancestor can not be null"); 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; + llvm_unreachable("must not reach here!"); } } // namespace clangd
Index: clang-tools-extra/clangd/unittests/TweakTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/TweakTests.cpp +++ clang-tools-extra/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; Index: clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp =================================================================== --- clang-tools-extra/clangd/refactor/tweaks/ExtractVariable.cpp +++ clang-tools-extra/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/clangd/Selection.cpp =================================================================== --- clang-tools-extra/clangd/Selection.cpp +++ clang-tools-extra/clangd/Selection.cpp @@ -359,12 +359,13 @@ if (!Root) return nullptr; for (const Node *Ancestor = Root;; Ancestor = Ancestor->Children.front()) { + assert(Ancestor && "Ancestor can not be null"); 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; + llvm_unreachable("must not reach here!"); } } // namespace clangd
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits