destroy local objects at the end of a compound statement

Hi All,

I am new to Clang, so may be missing something obvious.

I am implementing a static analyser and I want to know when objects are constructed and deleted:

MyClass c;

in this case, I climb the Ast and visit a CXXConstructExpr but nothing to tell me about the implied destroy. I could reverse iterate through the compound statement and look for declarations etc. But I was not expecting to have to do this.


Information like this is actually quite difficult; it's not handled at the AST level. The Clang Static Analyzer uses Clang's CFG to handle this, though you have to pass it extra options to get it to include destructors. Note, however, that the CFG currently does not handle destructors for temporaries, because of this:

// Creates a temporary Foo whose lifetime now matches that of 'foo'.
const Foo &foo = coin() ? Foo(1) : Foo(0);

Clang's IRGen ("CodeGen") libraries have their own handling of this, which I haven't studied in detail yet. I'm sure I'll get there eventually once the analyzer starts handling temporary destructors.


Hi Jordan,

Thanks for this. After more thought, I realised that it was not going to be so simple.