Skip to content

Commit 1258747

Browse files
committed
[clangd] Fix a semantic-highlighting crash.
Differential Revision: https://reviews.llvm.org/D137064
1 parent e0b40af commit 1258747

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang-tools-extra/clangd/SemanticHighlighting.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,9 @@ class CollectExtraHighlightings
661661
}
662662

663663
bool VisitCXXMemberCallExpr(CXXMemberCallExpr *CE) {
664-
if (isa<CXXDestructorDecl>(CE->getMethodDecl())) {
664+
// getMethodDecl can return nullptr with member pointers, e.g.
665+
// `(foo.*pointer_to_member_fun)(arg);`
666+
if (isa_and_present<CXXDestructorDecl>(CE->getMethodDecl())) {
665667
if (auto *ME = dyn_cast<MemberExpr>(CE->getCallee())) {
666668
if (auto *TI = ME->getMemberNameInfo().getNamedTypeInfo()) {
667669
H.addExtraModifier(TI->getTypeLoc().getBeginLoc(),

clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,17 @@ sizeof...($TemplateParameter[[Elements]]);
887887
$TemplateParameter[[T]] $Variable_def[[x]] = {};
888888
template <>
889889
int $Variable_def[[x]]<int> = (int)sizeof($Class[[Base]]);
890+
)cpp",
891+
// no crash
892+
R"cpp(
893+
struct $Class_def[[Foo]] {
894+
void $Method_decl[[foo]]();
895+
};
896+
897+
void $Function_def[[s]]($Class[[Foo]] $Parameter_def[[f]]) {
898+
auto $LocalVariable_def[[k]] = &$Class[[Foo]]::$Method[[foo]];
899+
($Parameter[[f]].*$LocalVariable[[k]])(); // no crash on VisitCXXMemberCallExpr
900+
}
890901
)cpp"};
891902
for (const auto &TestCase : TestCases)
892903
// Mask off scope modifiers to keep the tests manageable.

0 commit comments

Comments
 (0)