From c491854e22742239573aa1ad0f252c9ec5d59192 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 4 Oct 2019 14:09:31 +0000 Subject: [PATCH] [clang-rename] Fix a crash when renaming a class without definition. Reviewers: sammccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68459 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373748 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Tooling/Refactoring/Rename/USRFindingAction.cpp | 4 ++++ test/clang-rename/ForwardClassDecl.cpp | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 test/clang-rename/ForwardClassDecl.cpp diff --git a/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp b/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp index b60616ecc8..e26248f50c 100644 --- a/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp +++ b/lib/Tooling/Refactoring/Rename/USRFindingAction.cpp @@ -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(RecordDecl)) diff --git a/test/clang-rename/ForwardClassDecl.cpp b/test/clang-rename/ForwardClassDecl.cpp new file mode 100644 index 0000000000..ef731a16d6 --- /dev/null +++ b/test/clang-rename/ForwardClassDecl.cpp @@ -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 -- 2.40.0