This is an archive of the discontinued LLVM Phabricator instance.

Add a method to obtain this SVal of a method that created given StackFrameCtx
Needs ReviewPublic

Authored by k-wisniewski on Nov 16 2016, 12:17 PM.

Details

Summary

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

k-wisniewski retitled this revision from to Add a method to obtain this SVal of a method that created given StackFrameCtx.
k-wisniewski updated this object.
k-wisniewski added subscribers: cfe-commits, NoQ.
NoQ edited edge metadata.Nov 16 2016, 12:41 PM

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.

dcoughlin edited edge metadata.Nov 16 2016, 3:35 PM

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
782

Why this overload of getCXXThis() and not the one taking a CXXMethodDecl?

k-wisniewski edited edge metadata.

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.

zaks.anna edited edge metadata.Nov 30 2016, 10:18 PM

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.