[cfe-dev] CallEvent::isCalled() alternative if a function is called by pointer

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Wed May 2 13:32:47 PDT 2018


On 5/2/18 3:58 AM, Artem Razin via cfe-dev wrote:
> Hi All,
>
> I hope this is right place to ask such a newbie question like the 
> following.
>
> I am trying to write a checker to catch potential handle leaks (it's 
> on Windows: a handle is closed by CloseHandle).
>
> So I took SimpleStreamChecker as a base, now my checkPreCall() checks 
> if "CloseHandle" is called. Call.isCalled() works great except one 
> case when CloseHandle is called by pointer. It happens because of 
> using a template class that took a pointer to closing function as 
> template parameter (useful to close different types of handles by 
> appropriate functions: FindClose, CloseHandle etc.).
>
> Call.dump() prints "&CloseHandle(this->m_h)" in this case, so it 
> understands that this a pointer and that this is a pointer of 
> CloseHandle.But how to "extract" the the identifier of CloseHandle?

I'm not quite understanding that dump, it looks a bit weird. What is the 
actual code under analysis? Could you see if you can get 
Call.getOriginExpr()->dump() and/or Call.getDecl()->dump()? These should 
be more informative.

In general the analyzer does indeed understand calls through function 
pointers, as long as it can at all be tracked by looking at the current 
execution path.

And when it is tracked, CallEvent::isCalled() should "just work" because 
it only looks at Call.getDecl() which should be the path-specific decl.

>
> Thank you in advance!
>
> -- 
> Best regards,
> Artem A. Razin
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180502/4cda3214/attachment.html>


More information about the cfe-dev mailing list