yaxunl added a comment.

In D70172#1772140 <https://reviews.llvm.org/D70172#1772140>, @rjmccall wrote:

> Richard is definitely our main expert in the implicit synthesis of special 
> members.  It seems to me that if we need the destructor declaration at some 
> point, we should be forcing it to exist at that point.


In AST there are no separate decls for deleting dtors and complete object 
dtors. In AST there are only complete object dtors. In codegen when clang emits 
the definition of a deleting dtor, clang uses GlobalDecl with Dtor_Deleting. 
However AST does not have that.

Since a deleting dtor is supposed to call a complete object dtor, clang needs 
to check the complete object dtor in the context of the deleting dtor. Since 
deleting dtor is synthesized in codegen and does not have a body, clang 
manually pushed the decl of the complete object dtor as context and checks the 
same complete object dtor.

One may consider using GlobalDecl to differentiate complete object dtor and 
deleting dtor in AST. However that requires to use GlobalDecl to replace Decl 
in many places in Sema, which seems to be an overkill.

Fortunately, we could identify the deleting dtor by context without using 
GlobalDecl.

There are two cases :

1. There is no definition of complete object dtor,

When clang checks a dtor, if the caller is itself and the caller has no 
definition. This can only happen when clang checks the deleting dtor. Clang 
should just assumes the dtor is emitted. Since the dtor has no definition, 
there is no deferred diagnostics emitted. Clang just add a call graph branch 
dtor->dtor to the call graph. There is no deferred diagnostics happening with 
the dtor since the deleting dtor only calls complete object dtor and 
deallocating functions which are not supposed to cause diagnostics.

Later, if the dtor is called in other functions and checked, since the caller 
is not itself, it is treated as a normal function, i.e., whether it is emitted 
is determined by whether it has definition. Since the deleting dtor does not 
have extra deferred diagnostics compared with complete object dtor, there is no 
need to differentiate whether the callee is deleting dtor or complet object 
dtor.

If the complete object dtor is defined, its callees and deferred diagnostics 
happening in its body will be recorded as normal functions. If the complete 
object dtor or deleting dtor is called by other functions, the deferred 
diagnotics of the complete object dtor will be emitted.

2. There is definition of complete object dtor.

Clang will not check the deleting dtor. In this case the complete object dtor 
will be checked as a normal function. As discussed in case 1, deleting dtor 
should result in the same deferred diagnotics as complete object dtor, 
therefore there is no need to differentiate call of deleting dtor and complete 
object dtor.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70172/new/

https://reviews.llvm.org/D70172



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to