Skip to content

Commit 448538d

Browse files
committed
Added boilerplate for plug-in transfer function support for CallExprs.
GRSimpleVals performs the following action: invalidate all values passed-by-reference. llvm-svn: 47638
1 parent f287e7d commit 448538d

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

clang/Analysis/GRSimpleVals.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "GRSimpleVals.h"
17+
#include "ValueState.h"
1718
#include "clang/Basic/Diagnostic.h"
1819

1920
using namespace clang;
@@ -329,3 +330,27 @@ RVal GRSimpleVals::EvalNE(ValueManager& ValMgr, LVal L, LVal R) {
329330

330331
return NonLVal::MakeIntTruthVal(ValMgr, true);
331332
}
333+
334+
//===----------------------------------------------------------------------===//
335+
// Transfer function for Function Calls.
336+
//===----------------------------------------------------------------------===//
337+
338+
ValueStateImpl*
339+
GRSimpleVals::EvalCall(ValueStateManager& StateMgr, ValueManager& ValMgr,
340+
CallExpr* CE, LVal L, ValueStateImpl* StImpl) {
341+
342+
ValueState St(StImpl);
343+
344+
// Invalidate all arguments passed in by reference (LVals).
345+
346+
for (CallExpr::arg_iterator I = CE->arg_begin(), E = CE->arg_end();
347+
I != E; ++I) {
348+
349+
RVal V = StateMgr.GetRVal(St, *I);
350+
351+
if (isa<LVal>(V))
352+
St = StateMgr.SetRVal(St, cast<LVal>(V), UnknownVal());
353+
}
354+
355+
return St.getImpl();
356+
}

clang/Analysis/GRSimpleVals.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class GRSimpleVals : public GRTransferFuncs {
5050
virtual RVal EvalBinOp(ValueManager& ValMgr, BinaryOperator::Opcode Op,
5151
LVal L, NonLVal R);
5252

53+
// Calls.
54+
55+
virtual ValueStateImpl* EvalCall(ValueStateManager& StateMgr,
56+
ValueManager& ValMgr,
57+
CallExpr* CE, LVal L,
58+
ValueStateImpl* StImpl);
59+
5360
protected:
5461

5562
// Equality operators for LVals.

clang/include/clang/Analysis/PathSensitive/GRExprEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class GRExprEngine {
410410
}
411411

412412
StateTy EvalCall(CallExpr* CE, LVal L, StateTy St) {
413-
return St;
413+
return StateTy(TF->EvalCall(StateMgr, ValMgr, CE, L, St.getImpl()));
414414
}
415415

416416
StateTy MarkBranch(StateTy St, Stmt* Terminator, bool branchTaken);

clang/include/clang/Analysis/PathSensitive/GRTransferFuncs.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
namespace clang {
2121

22+
class ValueStateImpl;
23+
class ValueStateManager;
24+
2225
class GRTransferFuncs {
2326
public:
2427
GRTransferFuncs() {}
@@ -47,6 +50,13 @@ class GRTransferFuncs {
4750

4851
virtual RVal EvalBinOp(ValueManager& ValMgr, BinaryOperator::Opcode Op,
4952
LVal L, NonLVal R) = 0;
53+
54+
// Calls.
55+
56+
virtual ValueStateImpl* EvalCall(ValueStateManager& StateMgr,
57+
ValueManager& ValMgr,
58+
CallExpr* CE, LVal L,
59+
ValueStateImpl* StImpl) = 0;
5060
};
5161

5262
} // end clang namespace

0 commit comments

Comments
 (0)