[cfe-dev] Static Analyzer: immortal objects and getting the symbol for 'this'

Gábor Kozár kozargabor at gmail.com
Sat Jul 13 10:30:53 PDT 2013


Hi,


I'm using the Clang Static Analyzer from Clang 3.3. I want to check
object's state when they die. I tried using checkDeadSymbols, but according
to the SymbolReaper, the objects of interest never die. This is my test
code:

struct Foo
{
     int* x;
     Foo() { x = new int(10); }
};

int main(int argc, const char** argv)
{
      Foo f;
      return 0;
}

The int* does die, but f does not. (I cannot check this directly: I just
made the SymbolReaper print all symbols are regions that died, using the
dead_begin(), etc. and region_begin() etc. methods). Why is this, and how
can I work around it?

Even when there is a user-made destructor, which I can get using
checkEndFunction, I'm unable to get back the symbol that represents 'f'. I
spent like an hour digging through clang::ento's reference, and this was my
best tip:

const CXXThisRegion* thisRegion =
context.getStoreManager().getRegionManager().getCXXThisRegion(
            dtor->getThisType(context.getASTContext()),
            context.getLocationContext());

Unfortunately, this gives something that doesn't seem to have anything to
do with 'f'. How can I get the symbol representing 'f', using only the
CheckerContext and the const CXXDestructorDecl* I can obtain from the
LocationContext?

I'm really stuck, and any help would be greatly appreciated. Thank you!

Gabor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130713/93c0a60e/attachment.html>


More information about the cfe-dev mailing list