kadircet created this revision. kadircet added a reviewer: hokein. Herald added subscribers: usaxena95, arphaman. kadircet requested review of this revision. Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov. Herald added a project: clang-tools-extra.
Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D101743 Files: clang-tools-extra/clangd/Hover.cpp clang-tools-extra/clangd/unittests/HoverTests.cpp Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2438,6 +2438,20 @@ } } +TEST(Hover, NoCrash) { + Annotations T(R"cpp( + /* error-ok */ + template<typename T> T foo(T); + + // Setter variable heuristic might fail if the callexpr is broken. + struct X { int Y; void [[^setY]](float) { Y = foo(x); } };)cpp"); + + TestTU TU = TestTU::withCode(T.code()); + auto AST = TU.build(); + for (const auto &P : T.points()) + getHover(AST, P, format::getLLVMStyle(), nullptr); +} + TEST(Hover, DocsFromMostSpecial) { Annotations T(R"cpp( // doc1 Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -505,7 +505,7 @@ if (auto *CE = llvm::dyn_cast<CallExpr>(RHS->IgnoreCasts())) { if (CE->getNumArgs() != 1) return llvm::None; - auto *ND = llvm::dyn_cast<NamedDecl>(CE->getCalleeDecl()); + auto *ND = llvm::dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl()); if (!ND || !ND->getIdentifier() || ND->getName() != "move" || !ND->isInStdNamespace()) return llvm::None;
Index: clang-tools-extra/clangd/unittests/HoverTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/HoverTests.cpp +++ clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -2438,6 +2438,20 @@ } } +TEST(Hover, NoCrash) { + Annotations T(R"cpp( + /* error-ok */ + template<typename T> T foo(T); + + // Setter variable heuristic might fail if the callexpr is broken. + struct X { int Y; void [[^setY]](float) { Y = foo(x); } };)cpp"); + + TestTU TU = TestTU::withCode(T.code()); + auto AST = TU.build(); + for (const auto &P : T.points()) + getHover(AST, P, format::getLLVMStyle(), nullptr); +} + TEST(Hover, DocsFromMostSpecial) { Annotations T(R"cpp( // doc1 Index: clang-tools-extra/clangd/Hover.cpp =================================================================== --- clang-tools-extra/clangd/Hover.cpp +++ clang-tools-extra/clangd/Hover.cpp @@ -505,7 +505,7 @@ if (auto *CE = llvm::dyn_cast<CallExpr>(RHS->IgnoreCasts())) { if (CE->getNumArgs() != 1) return llvm::None; - auto *ND = llvm::dyn_cast<NamedDecl>(CE->getCalleeDecl()); + auto *ND = llvm::dyn_cast_or_null<NamedDecl>(CE->getCalleeDecl()); if (!ND || !ND->getIdentifier() || ND->getName() != "move" || !ND->isInStdNamespace()) return llvm::None;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits