[cfe-dev] Question about how to extract information about the calling object

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Thu Jun 28 10:12:14 PDT 2018


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.


On 6/27/18 6:35 PM, Zack Coker via cfe-dev wrote:
> Hello,
>
> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list