[PATCH] D44536: Avoid segfault when destructor is not yet known

John McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 28 21:41:18 PDT 2018


rjmccall added a comment.

In https://reviews.llvm.org/D44536#1051181, @ahatanak wrote:

> I see, so Sema::CheckCompletedCXXClass probably isn't the right place to call DeclareImplicitDestructor as that could significantly increase the size of the AST.


Right.  Again, I'd like Richard to weigh in here, but my suspicion would be that, somehow, the fact that e is an incomplete type when we type-check that call is combining poorly with the fact that it's declared by the time that we generate IR for it.  We probably do not record the existence of a pre-emptive use of the destructor.  There is no other way to get into this situation because every other thing that cares about the existence of a destructor requires a complete type.

That probably points to the solution here.  We've already emitted a warning that the code is doing a trivial deletion.  We should set a flag in the CXXDeleteExpr saying that the destructor is trivial, based on what we found in Sema, and in IRGen we should honor that flag before actually looking at the type.

For what it's worth, I believe this test case has undefined behavior: we're [i]allowed[/i] to treat it as a deletion of an incomplete type and not actually call the destructor, because that was true at the point where we type-checked the call.  Arguably we should just set a flag in the CXXDeleteExpr


Repository:
  rC Clang

https://reviews.llvm.org/D44536





More information about the cfe-commits mailing list