[clang-rename] Fix a crash when renaming a class without definition.
authorHaojian Wu <hokein@google.com>
Fri, 4 Oct 2019 14:09:31 +0000 (14:09 +0000)
committerHaojian Wu <hokein@google.com>
Fri, 4 Oct 2019 14:09:31 +0000 (14:09 +0000)
Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68459

llvm-svn: 373748

clang/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp
clang/test/clang-rename/ForwardClassDecl.cpp [new file with mode: 0644]

index b60616e..e26248f 100644 (file)
@@ -102,6 +102,10 @@ public:
 
 private:
   void handleCXXRecordDecl(const CXXRecordDecl *RecordDecl) {
+    if (!RecordDecl->getDefinition()) {
+      USRSet.insert(getUSRForDecl(RecordDecl));
+      return;
+    }
     RecordDecl = RecordDecl->getDefinition();
     if (const auto *ClassTemplateSpecDecl =
             dyn_cast<ClassTemplateSpecializationDecl>(RecordDecl))
diff --git a/clang/test/clang-rename/ForwardClassDecl.cpp b/clang/test/clang-rename/ForwardClassDecl.cpp
new file mode 100644 (file)
index 0000000..ef731a1
--- /dev/null
@@ -0,0 +1,4 @@
+class Foo; // CHECK: class Bar;
+Foo *f();  // CHECK: Bar *f();
+
+// RUN: clang-rename -offset=6 -new-name=Bar %s --  | sed 's,//.*,,' | FileCheck %s