[clang-tools-extra] 46dbd19 - [clangd] Fix nullptr crash in AddUsing tweak on catch(...)

Sam McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 21 10:56:56 PDT 2022


Author: Sam McCall
Date: 2022-03-21T18:56:45+01:00
New Revision: 46dbd19afb79c5c81ccb87cee9e41ad668b35324

URL: https://github.com/llvm/llvm-project/commit/46dbd19afb79c5c81ccb87cee9e41ad668b35324
DIFF: https://github.com/llvm/llvm-project/commit/46dbd19afb79c5c81ccb87cee9e41ad668b35324.diff

LOG: [clangd] Fix nullptr crash in AddUsing tweak on catch(...)

Fixes https://github.com/clangd/clangd/issues/1072

Added: 
    

Modified: 
    clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
    clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
index a75c4852bf751..5a4e1aa571a74 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/AddUsing.cpp
@@ -78,6 +78,8 @@ class UsingFinder : public RecursiveASTVisitor<UsingFinder> {
   }
 
   bool TraverseDecl(Decl *Node) {
+    if (!Node)
+      return true;
     // There is no need to go deeper into nodes that do not enclose selection,
     // since "using" there will not affect selection, nor would it make a good
     // insertion point.

diff  --git a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
index b9b5cf49d2db0..662000a47b704 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/AddUsingTests.cpp
@@ -78,6 +78,19 @@ class cc {
   EXPECT_UNAVAILABLE(Header + "void fun() { one::two::f^f(); }");
 }
 
+TEST_F(AddUsingTest, Crash1072) {
+  // Used to crash when traversing catch(...)
+  // https://github.com/clangd/clangd/issues/1072
+  const char *Code = R"cpp(
+  namespace ns { class A; }
+  ns::^A *err;
+  void catchall() {
+    try {} catch(...) {}
+  }
+  )cpp";
+  EXPECT_AVAILABLE(Code);
+}
+
 TEST_F(AddUsingTest, Apply) {
   FileName = "test.cpp";
   struct {


        


More information about the cfe-commits mailing list