Ted Kremenek | 36cf32c | 2008-04-16 18:39:25 +0000 | [diff] [blame] | 1 | //== GRTransferFuncs.cpp - Path-Sens. Transfer Functions Interface -*- C++ -*--= |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines GRTransferFuncs, which provides a base-class that |
| 11 | // defines an interface for transfer functions used by GRExprEngine. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Analysis/PathSensitive/GRTransferFuncs.h" |
Ted Kremenek | 7aef484 | 2008-04-16 20:40:59 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/PathSensitive/GRExprEngine.h" |
Ted Kremenek | 36cf32c | 2008-04-16 18:39:25 +0000 | [diff] [blame] | 17 | |
| 18 | using namespace clang; |
| 19 | |
| 20 | void GRTransferFuncs::RegisterChecks(GRExprEngine& Eng) {} |
Ted Kremenek | 7aef484 | 2008-04-16 20:40:59 +0000 | [diff] [blame] | 21 | |
| 22 | void GRTransferFuncs::EvalStore(ExplodedNodeSet<ValueState>& Dst, |
| 23 | GRExprEngine& Eng, |
| 24 | GRStmtNodeBuilder<ValueState>& Builder, |
| 25 | Expr* E, ExplodedNode<ValueState>* Pred, |
Ted Kremenek | f22f868 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 26 | const ValueState* St, RVal TargetLV, RVal Val) { |
Ted Kremenek | 7aef484 | 2008-04-16 20:40:59 +0000 | [diff] [blame] | 27 | |
| 28 | // This code basically matches the "safety-net" logic of GRExprEngine: |
| 29 | // bind Val to TargetLV, and create a new node. We replicate it here |
| 30 | // because subclasses of GRTransferFuncs may wish to call it. |
| 31 | |
| 32 | assert (!TargetLV.isUndef()); |
| 33 | |
| 34 | if (TargetLV.isUnknown()) |
| 35 | Builder.MakeNode(Dst, E, Pred, St); |
| 36 | else |
| 37 | Builder.MakeNode(Dst, E, Pred, |
| 38 | Eng.getStateManager().SetRVal(St, cast<LVal>(TargetLV), Val)); |
| 39 | } |
Ted Kremenek | fa81dff | 2008-07-17 21:27:31 +0000 | [diff] [blame] | 40 | |
Ted Kremenek | 9c4ce60 | 2008-07-18 05:53:58 +0000 | [diff] [blame] | 41 | void GRTransferFuncs::EvalBinOpNN(ValueStateSet& OStates, |
| 42 | ValueStateManager& StateMgr, |
| 43 | const ValueState *St, Expr* Ex, |
Ted Kremenek | fa81dff | 2008-07-17 21:27:31 +0000 | [diff] [blame] | 44 | BinaryOperator::Opcode Op, |
Ted Kremenek | 9c4ce60 | 2008-07-18 05:53:58 +0000 | [diff] [blame] | 45 | NonLVal L, NonLVal R) { |
Ted Kremenek | fa81dff | 2008-07-17 21:27:31 +0000 | [diff] [blame] | 46 | |
Ted Kremenek | 589f881 | 2008-07-18 15:27:58 +0000 | [diff] [blame] | 47 | OStates.Add(StateMgr.SetRVal(St, Ex, DetermEvalBinOpNN(StateMgr, Op, L, R))); |
Ted Kremenek | fa81dff | 2008-07-17 21:27:31 +0000 | [diff] [blame] | 48 | } |