[cfe-dev] destroy local objects at the end of a compound statement

Jordan Rose jordan_rose at apple.com
Fri Dec 7 11:20:27 PST 2012


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.

Jordan


On Dec 7, 2012, at 5:31 , peter jacobsen <jacobsen.peter at gmail.com> wrote:

> 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.
> 
> Thanks,
> Peter
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list