Page MenuHomePhabricator
Paste P8043

Crasher - r316869
ActivePublic

Authored by dlj on Nov 5 2017, 1:41 PM.
/*
Run with:
bin/clang -cc1 -triple x86_64-grtev4-linux-gnu -emit-obj -O3 -std=gnu++11 -fexperimental-new-pass-manager -x c++ crasher.cc
*/
template <typename T>
struct TempPtr {
explicit TempPtr(T* ptr) : p_(ptr) {}
~TempPtr() { delete p_; }
T* leak() const {
T* ptr = p_;
p_ = 0;
return ptr;
}
mutable T* p_;
};
template <typename T>
struct Ptr {
Ptr(TempPtr<T>&& o) : p_(o.leak()) {}
TempPtr<T> release() {
T* ptr = p_;
p_ = 0;
return TempPtr<T>(ptr);
}
T* operator->() const {
if (!p_) __builtin_trap();
return p_;
}
operator bool() const { return p_; }
T* p_;
};
struct C {
~C();
Ptr<C> x_;
};
struct Deleter {
void handle(TempPtr<C>&&);
};
C::~C()
{
if (!x_)
return;
Deleter d;
Ptr<C> current = x_.release();
while (true) {
Ptr<C> next = current->x_.release();
d.handle(current.release());
if (!next)
break;
current = next.release();
}
}

Event Timeline

dlj created this paste.Nov 5 2017, 1:41 PM
dlj created this object with visibility "Public (No Login Required)".
dlj created this object with edit policy "dlj (David L. Jones)".
dlj edited the content of this paste. (Show Details)