Fixes
struct A {
~A();
};
struct B {
A a;
};
struct C {
union { B b; }; ~C() noexcept;
};
C::~C() noexcept {}
Differential D10508
[Clang/CodeGen] Prevent crash if destructor class is not accessible davide on Jun 17 2015, 10:30 AM. Authored by
Details
Fixes struct A { ~A(); }; struct B { A a; }; struct C { union { B b; }; ~C() noexcept; }; C::~C() noexcept {}
Diff Detail Event TimelineComment Actions + Anders Carlsson who originally wrote the code (apparently he's not
Comment Actions Reordered checks as suggested. Comment Actions Um. I don't mind us being a little more defensive in IR-gen, but the right fix for this code is that it needs to be handled / diagnosed by Sema. Comment Actions Thank you for your reply John. Sorry if I submitted this before hearing back from you. Thanks!
Comment Actions Richard: this code is already testing hasTrivialDestructor. If you would be comfortable with declaring a trivial destructor except for performance reasons, maybe hasTrivialDestructor should be returning true? Comment Actions I'm fine with saying that the destructor is non-trivial when it's deleted like this; it just seemed inconsistent with your statement that we could make Sema declare a trivial destructor but it would be wasteful. Certainly I don't think we want hasTrivialDestructor and getDestructor()->isTrivial() to return different things. If we're going to leave hasTrivialDestructor returning false, then I agree that the best fix is to repeat the logic from Sema that completely skips the field. Comment Actions If we do that, we should remove the defensive code from IR-gen, because the less-defensive code is serving the admirable purpose of detecting this problem by causing this assertion. |
I suspect you want to reorder these checks. The triviality check is a bittest, and getDestructor() may perform lookup.