[PATCH] D26760: Add the way to extract SVals of arguments used in a call for a given StackFrameCtx
Krzysztof Wiśniewski via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 16 12:06:20 PST 2016
k-wisniewski created this revision.
k-wisniewski added reviewers: a.sidorin, NoQ, dcoughlin, zaks.anna.
k-wisniewski added a subscriber: cfe-commits.
This patch adds getArgsSVal method to ProgramState that allows the user to obtain SVals of argumetns used in a call that created the given StackFrameCtx. I know this isn't perfect (Alexey Sidorin pointed out that there is a problem with line 741 - argument values may be overwritten) but wanted to submit it separate from other changes that I do and find _the_ right solution.
https://reviews.llvm.org/D26760
Files:
include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
Index: include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
===================================================================
--- include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -294,6 +294,10 @@
/// Get the lvalue for an array index.
SVal getLValue(QualType ElementType, SVal Idx, SVal Base) const;
+ /// Get the symbolic value of arguments used in a call
+ /// that created the given stack frame
+ SVal getArgSVal(const StackFrameContext *SFC, const unsigned ArgIdx) const;
+
/// Returns the SVal bound to the statement 'S' in the state's environment.
SVal getSVal(const Stmt *S, const LocationContext *LCtx) const;
@@ -725,6 +729,28 @@
return UnknownVal();
}
+inline SVal ProgramState::getArgSVal(const StackFrameContext *SFC,
+ const unsigned ArgIdx) const {
+ const FunctionDecl *FunctionDecl = SFC->getDecl()->getAsFunction();
+ unsigned NumArgs = FunctionDecl->getNumParams();
+ assert(ArgIdx < NumArgs && "Arg access out of range!");
+
+ if (SFC->inTopFrame()) {
+ // if we are in the top frame we don't have any arguments bound in the store
+ // because the call wasn't modeled in the first place.
+ const VarDecl *ArgDecl = FunctionDecl->parameters()[ArgIdx];
+ const Loc ArgLoc = getLValue(ArgDecl, SFC);
+ return getSVal(ArgLoc);
+ } else {
+ // in this case we need to ask the environment as the arguments' memory
+ // region may have been purged as no longer needed.
+ const Stmt *callSite = SFC->getCallSite();
+ const CallExpr *callSiteExpr = dyn_cast<CallExpr>(callSite);
+ const Expr *argExpr = callSiteExpr->getArg(ArgIdx);
+ return getSVal(argExpr, SFC->getParent());
+ }
+}
+
inline SVal ProgramState::getSVal(const Stmt *Ex,
const LocationContext *LCtx) const{
return Env.getSVal(EnvironmentEntry(Ex, LCtx),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26760.78241.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161116/df16bc1e/attachment.bin>
More information about the cfe-commits
mailing list