[PATCH] D137064: [clangd] Fix a semantic-highlighting crash.

Haojian Wu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 03:19:29 PDT 2022


This revision was automatically updated to reflect the committed changes.
hokein marked 2 inline comments as done.
Closed by commit rG1258747a59db: [clangd] Fix a semantic-highlighting crash. (authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D137064?vs=471930&id=471947#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137064/new/

https://reviews.llvm.org/D137064

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -887,6 +887,17 @@
         $TemplateParameter[[T]] $Variable_def[[x]] = {};
         template <>
         int $Variable_def[[x]]<int> = (int)sizeof($Class[[Base]]);
+      )cpp",
+      // no crash
+      R"cpp(
+        struct $Class_def[[Foo]] {
+          void $Method_decl[[foo]]();
+        };
+
+        void $Function_def[[s]]($Class[[Foo]] $Parameter_def[[f]]) {
+          auto $LocalVariable_def[[k]] = &$Class[[Foo]]::$Method[[foo]];
+          ($Parameter[[f]].*$LocalVariable[[k]])(); // no crash on VisitCXXMemberCallExpr
+        }
       )cpp"};
   for (const auto &TestCase : TestCases)
     // Mask off scope modifiers to keep the tests manageable.
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===================================================================
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -661,7 +661,9 @@
   }
 
   bool VisitCXXMemberCallExpr(CXXMemberCallExpr *CE) {
-    if (isa<CXXDestructorDecl>(CE->getMethodDecl())) {
+    // getMethodDecl can return nullptr with member pointers, e.g.
+    // `(foo.*pointer_to_member_fun)(arg);`
+    if (isa_and_present<CXXDestructorDecl>(CE->getMethodDecl())) {
       if (auto *ME = dyn_cast<MemberExpr>(CE->getCallee())) {
         if (auto *TI = ME->getMemberNameInfo().getNamedTypeInfo()) {
           H.addExtraModifier(TI->getTypeLoc().getBeginLoc(),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137064.471947.patch
Type: text/x-patch
Size: 1696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221031/ec9a8711/attachment.bin>


More information about the cfe-commits mailing list