mirror of
https://github.com/intel/llvm.git
synced 2026-02-09 01:52:26 +08:00
Ensure that APIRecords get destroyed correctly.
Implements an APISet specific unique ptr type that has a custom deleter that just calls the underlying APIRecord subclass destructor.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Support/Allocator.h"
|
||||
#include "llvm/Support/Casting.h"
|
||||
#include <memory>
|
||||
|
||||
namespace clang {
|
||||
namespace symbolgraph {
|
||||
@@ -120,7 +121,25 @@ public:
|
||||
StringRef copyString(StringRef String, llvm::BumpPtrAllocator &Allocator);
|
||||
StringRef copyString(StringRef String);
|
||||
|
||||
using GlobalRecordMap = llvm::MapVector<StringRef, GlobalRecord *>;
|
||||
private:
|
||||
/// \brief A custom deleter used for ``std::unique_ptr`` to APIRecords stored
|
||||
/// in the BumpPtrAllocator.
|
||||
///
|
||||
/// \tparam T the exact type of the APIRecord subclass.
|
||||
template <typename T> struct UniquePtrBumpPtrAllocatorDeleter {
|
||||
void operator()(T *Instance) { Instance->~T(); }
|
||||
};
|
||||
|
||||
public:
|
||||
/// A unique pointer to an APIRecord stored in the BumpPtrAllocator.
|
||||
///
|
||||
/// \tparam T the exact type of the APIRecord subclass.
|
||||
template <typename T>
|
||||
using APIRecordUniquePtr =
|
||||
std::unique_ptr<T, UniquePtrBumpPtrAllocatorDeleter<T>>;
|
||||
|
||||
using GlobalRecordMap =
|
||||
llvm::MapVector<StringRef, APIRecordUniquePtr<GlobalRecord>>;
|
||||
|
||||
const GlobalRecordMap &getGlobals() const { return Globals; }
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ GlobalRecord *APISet::addGlobal(GVKind Kind, StringRef Name, StringRef USR,
|
||||
FunctionSignature Signature) {
|
||||
auto Result = Globals.insert({Name, nullptr});
|
||||
if (Result.second) {
|
||||
GlobalRecord *Record = new (Allocator)
|
||||
GlobalRecord{Kind, Name, USR, Loc, Availability,
|
||||
Linkage, Comment, Fragments, SubHeading, Signature};
|
||||
Result.first->second = Record;
|
||||
auto Record = APIRecordUniquePtr<GlobalRecord>(new (Allocator) GlobalRecord{
|
||||
Kind, Name, USR, Loc, Availability, Linkage, Comment, Fragments,
|
||||
SubHeading, Signature});
|
||||
Result.first->second = std::move(Record);
|
||||
}
|
||||
return Result.first->second;
|
||||
return Result.first->second.get();
|
||||
}
|
||||
|
||||
GlobalRecord *
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// FIXME: disable the test to unblock build bots
|
||||
// UNSUPPORTED: true
|
||||
// RUN: rm -rf %t
|
||||
// RUN: split-file %s %t
|
||||
// RUN: sed -e "s@INPUT_DIR@%/t@g" %t/reference.output.json.in >> \
|
||||
|
||||
Reference in New Issue
Block a user