[clang-tools-extra] [clangd] Avoid crash when summarizing pointer-to-member expr for block-end hint (PR #76492)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 27 23:48:51 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clangd
Author: Nathan Ridge (HighCommander4)
<details>
<summary>Changes</summary>
Fixes https://github.com/clangd/clangd/issues/1873
---
Full diff: https://github.com/llvm/llvm-project/pull/76492.diff
2 Files Affected:
- (modified) clang-tools-extra/clangd/InlayHints.cpp (+1-1)
- (modified) clang-tools-extra/clangd/unittests/InlayHintTests.cpp (+13)
``````````diff
diff --git a/clang-tools-extra/clangd/InlayHints.cpp b/clang-tools-extra/clangd/InlayHints.cpp
index 3da047f9542138..fd28b48b5a0b02 100644
--- a/clang-tools-extra/clangd/InlayHints.cpp
+++ b/clang-tools-extra/clangd/InlayHints.cpp
@@ -286,7 +286,7 @@ std::string summarizeExpr(const Expr *E) {
// Step through implicit nodes that clang doesn't classify as such.
std::string VisitCXXMemberCallExpr(const CXXMemberCallExpr *E) {
// Call to operator bool() inside if (X): dispatch to X.
- if (E->getNumArgs() == 0 &&
+ if (E->getNumArgs() == 0 && E->getMethodDecl() &&
E->getMethodDecl()->getDeclName().getNameKind() ==
DeclarationName::CXXConversionFunctionName &&
E->getSourceRange() ==
diff --git a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
index 20c1cdd985dbc0..ea5ee18f1da65c 100644
--- a/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
+++ b/clang-tools-extra/clangd/unittests/InlayHintTests.cpp
@@ -2172,6 +2172,19 @@ TEST(BlockEndHints, Macro) {
ExpectedHint{" // struct S1", "S1"});
}
+TEST(BlockEndHints, PointerToMemberFunction) {
+ // Do not crash trying to summarize `a->*p`.
+ assertBlockEndHints(R"cpp(
+ class A {};
+ using Predicate = bool(A::*)();
+ void foo(A* a, Predicate p) {
+ if ((a->*p)()) {
+ $ptrmem[[}]]
+ } // suppress
+ )cpp",
+ ExpectedHint{" // if", "ptrmem"});
+}
+
// FIXME: Low-hanging fruit where we could omit a type hint:
// - auto x = TypeName(...);
// - auto x = (TypeName) (...);
``````````
</details>
https://github.com/llvm/llvm-project/pull/76492
More information about the cfe-commits
mailing list