Artem Dergachev (@NoQ ) helped me correctly handle C++ method calls in my RecursionChecker (that finds infnite recursion) and this is the method that I use to obtain SVal of "this" parameter of a method call represented by StackFrameCtx.
Diff Detail
Event Timeline
I think this method, unlike D26760, doesn't have the problem with overwriting the location in the top frame, because the location of C++ "this" cannot really be assigned to.
Thanks for the patch!
How does this differ from getCXXThisVal() on CXXInstanceCall and its subclasses in CallEvent.h? Can that be used instead? Or are there places where you need access to this without a CallEvent?
Also: it seems like there are a lot of places in the analyzer codebase that do this dance (get the 'this' pointer, load from it). Can they be safely replaced with calls to this helper? If so, that would be awesome.
include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h | ||
---|---|---|
769 | Why this overload of getCXXThis() and not the one taking a CXXMethodDecl? |
I have added method for getting Objective-C message receivers (as it is related somewhat). This might however be broken for super calls as @NoQ told me as I was writing this comment. @dcoughlin - yes, there are cases when I don't have call event and need to get SVal for instance with which the method was called. The example is when I go up the call stack in RecursionChecker. I have changed CXXRecordDecl to CXXMethodDecl following your suggestion.
I see. You are handling more types of calls with this API! However, Similarly to the comment in the related patch, I think we should reuse the logic from CallEvent.
Why this overload of getCXXThis() and not the one taking a CXXMethodDecl?