Question about how to extract information about the calling object


Thanks for letting me join this mailing list.

I’m a PhD student trying to write experimental c++ static analysis checks for ROS.

I’m having trouble extracting the type of the calling object using a CheckerDocumentation method. For the line of code a.close(), after identifying that close() is a method of interest, I’d like to be able to identify that a is of type Bar or some subclass of Bar.

I’ve tried to look through all the documentation resources on the website and have spent a couple of days trying to investigate the problem - reading example checkers that seem like they are trying to do something similar. I may have missed something important, but I have been unable to find out how to extract this information.

If you could point me in the right direction, I’d appreciate it!

Zack Coker

If you're looking for the type of the object on which the method is called, look at CXXMemberCallExpr->getImplicitObjectArgument()->getType().

If you're looking for the declaration of the class on which the method is defined, look at CXXMethodDecl->getParent(). This may be a base class of the class of the this-argument.

Finally, if you're writing a path-sensitive StaticAnalyzer checker and want to find out the dynamic type of the object on which the method is called on the current path, use getDynamicTypeInfo(CXXInstanceCall.getCXXThis().getAsRegion()). It might be a more derived class.