Index: clang/include/clang/ASTMatchers/Dynamic/VariantValue.h =================================================================== --- clang/include/clang/ASTMatchers/Dynamic/VariantValue.h +++ clang/include/clang/ASTMatchers/Dynamic/VariantValue.h @@ -119,9 +119,9 @@ /// \brief Payload interface to be specialized by each matcher type. /// /// It follows a similar interface as VariantMatcher itself. - class Payload : public RefCountedBaseVPTR { + class Payload : public RefCountedBase { public: - ~Payload() override; + virtual ~Payload(); virtual llvm::Optional getSingleMatcher() const = 0; virtual std::string getTypeAsString() const = 0; virtual llvm::Optional Index: clang/include/clang/Basic/LLVM.h =================================================================== --- clang/include/clang/Basic/LLVM.h +++ clang/include/clang/Basic/LLVM.h @@ -43,7 +43,6 @@ template class IntrusiveRefCntPtr; template struct IntrusiveRefCntPtrInfo; template class RefCountedBase; - class RefCountedBaseVPTR; class raw_ostream; class raw_pwrite_stream; @@ -76,7 +75,6 @@ using llvm::IntrusiveRefCntPtr; using llvm::IntrusiveRefCntPtrInfo; using llvm::RefCountedBase; - using llvm::RefCountedBaseVPTR; using llvm::raw_ostream; using llvm::raw_pwrite_stream; Index: clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h =================================================================== --- clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -334,7 +334,7 @@ // Path "pieces" for path-sensitive diagnostics. //===----------------------------------------------------------------------===// -class PathDiagnosticPiece : public RefCountedBaseVPTR { +class PathDiagnosticPiece : public RefCountedBase { public: enum Kind { ControlFlow, Event, Macro, Call, Note }; enum DisplayHint { Above, Below }; @@ -366,7 +366,7 @@ PathDiagnosticPiece(Kind k, DisplayHint hint = Below); public: - ~PathDiagnosticPiece() override; + virtual ~PathDiagnosticPiece(); StringRef getString() const { return str; } Index: llvm/include/llvm/ADT/IntrusiveRefCntPtr.h =================================================================== --- llvm/include/llvm/ADT/IntrusiveRefCntPtr.h +++ llvm/include/llvm/ADT/IntrusiveRefCntPtr.h @@ -9,9 +9,9 @@ // // This file defines IntrusiveRefCntPtr, a template class that // implements a "smart" pointer for objects that maintain their own -// internal reference count, and RefCountedBase/RefCountedBaseVPTR, two -// generic base classes for objects that wish to have their lifetimes -// managed using reference counting. +// internal reference count, and RefCountedBase, a generic base class +// for objects that wish to have their lifetimes managed using reference +// counting. // // IntrusiveRefCntPtr is similar to Boost's intrusive_ptr with added // LLVM-style casting. @@ -52,36 +52,6 @@ } }; -//===----------------------------------------------------------------------===// -/// RefCountedBaseVPTR - A class that has the same function as -/// RefCountedBase, but with a virtual destructor. Should be used -/// instead of RefCountedBase for classes that already have virtual -/// methods to enforce dynamic allocation via 'new'. Classes that -/// inherit from RefCountedBaseVPTR can't be allocated on stack - -/// attempting to do this will produce a compile error. -//===----------------------------------------------------------------------===// - class RefCountedBaseVPTR { - mutable unsigned ref_cnt = 0; - - virtual void anchor(); - - protected: - RefCountedBaseVPTR() = default; - RefCountedBaseVPTR(const RefCountedBaseVPTR &) : ref_cnt(0) {} - - virtual ~RefCountedBaseVPTR() = default; - - void Retain() const { ++ref_cnt; } - void Release() const { - assert (ref_cnt > 0 && "Reference count is already zero."); - if (--ref_cnt == 0) delete this; - } - - template - friend struct IntrusiveRefCntPtrInfo; - }; - - template struct IntrusiveRefCntPtrInfo { static void retain(T *obj) { obj->Retain(); } static void release(T *obj) { obj->Release(); } @@ -124,10 +94,9 @@ /// wrapping NULL pointers. /// /// Reference counting is implemented via calls to -/// Obj->Retain()/Obj->Release(). Release() is required to destroy -/// the object when the reference count reaches zero. Inheriting from -/// RefCountedBase/RefCountedBaseVPTR takes care of this -/// automatically. +/// Obj->Retain()/Obj->Release(). Release() is required to destroy the +/// object when the reference count reaches zero. Inheriting from +/// RefCountedBase takes care of this automatically. //===----------------------------------------------------------------------===// template class IntrusiveRefCntPtr { Index: llvm/lib/Support/CMakeLists.txt =================================================================== --- llvm/lib/Support/CMakeLists.txt +++ llvm/lib/Support/CMakeLists.txt @@ -61,7 +61,6 @@ Hashing.cpp IntEqClasses.cpp IntervalMap.cpp - IntrusiveRefCntPtr.cpp JamCRC.cpp LEB128.cpp LineIterator.cpp Index: llvm/lib/Support/IntrusiveRefCntPtr.cpp =================================================================== --- llvm/lib/Support/IntrusiveRefCntPtr.cpp +++ /dev/null @@ -1,14 +0,0 @@ -//== IntrusiveRefCntPtr.cpp - Smart Refcounting Pointer ----------*- C++ -*-==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/IntrusiveRefCntPtr.h" - -using namespace llvm; - -void RefCountedBaseVPTR::anchor() { } Index: llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp =================================================================== --- llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp +++ llvm/unittests/ADT/IntrusiveRefCntPtrTest.cpp @@ -11,19 +11,29 @@ #include "gtest/gtest.h" namespace { -struct VirtualRefCounted : public llvm::RefCountedBaseVPTR { +struct VirtualRefCounted : public llvm::RefCountedBase { + VirtualRefCounted() { ++NumInstances; } + VirtualRefCounted(const VirtualRefCounted &) { ++NumInstances; } + virtual ~VirtualRefCounted() { --NumInstances; } virtual void f() {} + + static int NumInstances; }; -} + +int VirtualRefCounted::NumInstances = 0; +} // anonymous namespace namespace llvm { -// Run this test with valgrind to detect memory leaks. -TEST(IntrusiveRefCntPtr, RefCountedBaseVPTRCopyDoesNotLeak) { - VirtualRefCounted *V1 = new VirtualRefCounted; - IntrusiveRefCntPtr R1 = V1; - VirtualRefCounted *V2 = new VirtualRefCounted(*V1); - IntrusiveRefCntPtr R2 = V2; +TEST(IntrusiveRefCntPtr, VirtualRefCountedCopyDoesNotLeak) { + { + VirtualRefCounted *V1 = new VirtualRefCounted; + IntrusiveRefCntPtr R1 = V1; + VirtualRefCounted *V2 = new VirtualRefCounted(*V1); + IntrusiveRefCntPtr R2 = V2; + EXPECT_EQ(2, VirtualRefCounted::NumInstances); + } + EXPECT_EQ(0, VirtualRefCounted::NumInstances); } struct SimpleRefCounted : public RefCountedBase {};