Analyzer - CXXDestructorCall functioning


I was implementing a SA checker when I ran into the next (problem?) :

Whenever I write a callback PostCall/PreCall with the next body:

if (dyn_cast(&Call))
llvm::errs() << “DtorCall\n”;

if (dyn_cast(Call.getDecl()))
llvm::errs() << “DtorDecl\n”;


Then I could not find a case where the cast to CXXDestructorCall is successful.

Running this simple “checker” on the below example emitted no output to errs:

class A {
int main()
A a;
A b;

However if change the inner block this way:

A b;



then “DtorDecl” is displayed which makes sense.

The detailed description of the CXXDestructorCall says:

Represents an implicit call to a C++ destructor.

This can occur at the end of a scope (for automatic objects), at the end of a full-expression (for temporaries), or as part of a delete.

My question is: Does “can” mean in this context that the callback is quite unreliable even in trivial cases or is it a bug and the destructor call should trigger?



In this case the call event is missing because A is Plain Old Data and needs no destructor. Even in -ast-dump, i don't see the destructor declaration, so assuming the dump is complete, i guess your dyn_cast<CXXDestructorDecl> is bound to fail. If you add, say, "~A(){}" to the class definition, the callback starts firing.

However, there might be more bugs in the area of destructors, especially when it comes to temporary objects.

The documentation you quoted sounds strange - at least, i expect this call event to work for *explicit* destructors.