From 448538d86054fb732d6ca873093334b7881dc4d8 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 26 Feb 2008 23:04:29 +0000 Subject: [PATCH] Added boilerplate for plug-in transfer function support for CallExprs. GRSimpleVals performs the following action: invalidate all values passed-by-reference. llvm-svn: 47638 --- clang/Analysis/GRSimpleVals.cpp | 25 +++++++++++++++++++ clang/Analysis/GRSimpleVals.h | 7 ++++++ .../Analysis/PathSensitive/GRExprEngine.h | 2 +- .../Analysis/PathSensitive/GRTransferFuncs.h | 10 ++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/clang/Analysis/GRSimpleVals.cpp b/clang/Analysis/GRSimpleVals.cpp index 549aa0bb4ff3..4d9dccf621e0 100644 --- a/clang/Analysis/GRSimpleVals.cpp +++ b/clang/Analysis/GRSimpleVals.cpp @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "GRSimpleVals.h" +#include "ValueState.h" #include "clang/Basic/Diagnostic.h" using namespace clang; @@ -329,3 +330,27 @@ RVal GRSimpleVals::EvalNE(ValueManager& ValMgr, LVal L, LVal R) { return NonLVal::MakeIntTruthVal(ValMgr, true); } + +//===----------------------------------------------------------------------===// +// Transfer function for Function Calls. +//===----------------------------------------------------------------------===// + +ValueStateImpl* +GRSimpleVals::EvalCall(ValueStateManager& StateMgr, ValueManager& ValMgr, + CallExpr* CE, LVal L, ValueStateImpl* StImpl) { + + ValueState St(StImpl); + + // Invalidate all arguments passed in by reference (LVals). + + for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end(); + I != E; ++I) { + + RVal V = StateMgr.GetRVal(St, *I); + + if (isa(V)) + St = StateMgr.SetRVal(St, cast(V), UnknownVal()); + } + + return St.getImpl(); +} diff --git a/clang/Analysis/GRSimpleVals.h b/clang/Analysis/GRSimpleVals.h index 870166e8f4b7..10d4acd4b9f2 100644 --- a/clang/Analysis/GRSimpleVals.h +++ b/clang/Analysis/GRSimpleVals.h @@ -50,6 +50,13 @@ public: virtual RVal EvalBinOp(ValueManager& ValMgr, BinaryOperator::Opcode Op, LVal L, NonLVal R); + // Calls. + + virtual ValueStateImpl* EvalCall(ValueStateManager& StateMgr, + ValueManager& ValMgr, + CallExpr* CE, LVal L, + ValueStateImpl* StImpl); + protected: // Equality operators for LVals. diff --git a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h index a5f88354b8f8..5c9092943bbd 100644 --- a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -410,7 +410,7 @@ protected: } StateTy EvalCall(CallExpr* CE, LVal L, StateTy St) { - return St; + return StateTy(TF->EvalCall(StateMgr, ValMgr, CE, L, St.getImpl())); } StateTy MarkBranch(StateTy St, Stmt* Terminator, bool branchTaken); diff --git a/clang/include/clang/Analysis/PathSensitive/GRTransferFuncs.h b/clang/include/clang/Analysis/PathSensitive/GRTransferFuncs.h index 2a8ec2b6f77c..b4953d6401de 100644 --- a/clang/include/clang/Analysis/PathSensitive/GRTransferFuncs.h +++ b/clang/include/clang/Analysis/PathSensitive/GRTransferFuncs.h @@ -19,6 +19,9 @@ namespace clang { + class ValueStateImpl; + class ValueStateManager; + class GRTransferFuncs { public: GRTransferFuncs() {} @@ -47,6 +50,13 @@ public: virtual RVal EvalBinOp(ValueManager& ValMgr, BinaryOperator::Opcode Op, LVal L, NonLVal R) = 0; + + // Calls. + + virtual ValueStateImpl* EvalCall(ValueStateManager& StateMgr, + ValueManager& ValMgr, + CallExpr* CE, LVal L, + ValueStateImpl* StImpl) = 0; }; } // end clang namespace