[PATCH] D49985: [ADT] ImmutableList no longer requires elements to be copy constructible
Umann Kristóf via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 06:22:02 PDT 2018
Szelethus added a comment.
I ran into a serious problem. It seems like `ImmutableList` doesn't run the destructor for `std::unique_ptr`s or `std::shared_ptr`s:
struct Obj {
~Obj() { llvm_unreachable(""); } // never called
};
using ObjRef = std::unique_ptr<Obj>; // same with std::shared_ptr
namespace llvm {
// Specializing FoldingSetTrait so we can store ObjRef objects in ImmutableList.
template <>
struct FoldingSetTrait<ObjRef> : public DefaultFoldingSetTrait<ObjRef> {
static void Profile(const ObjRef &FN, FoldingSetNodeID &ID) {
ID.AddPointer(FN.get());
}
};
} // end of namespace llvm
TEST_F(ImmutableListTest, UniquePtrTest) {
ImmutableList<ObjRef>::Factory f;
ImmutableList<ObjRef> L = f.create(ObjRef(new Obj));
}
What is very interesting though, a simple wrapper works perfectly:
struct ObjRef {
Obj *ptr;
ObjRef(Obj *ptr) : ptr(ptr) {}
~ObjRef() { delete ptr; }
Obj *get() const { return ptr; }
};
// llvm_unreachable is actually reached in Obj::~Obj().
I've been stuck on this issue for a while now. Do you know anything about why this could happen?
https://reviews.llvm.org/D49985
More information about the llvm-commits
mailing list