aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/GRTransferFuncs.cpp
blob: cf32a073c1ede703871e0c972e945e9ec62210ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//== GRTransferFuncs.cpp - Path-Sens. Transfer Functions Interface -*- C++ -*--=
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This file defines GRTransferFuncs, which provides a base-class that
//  defines an interface for transfer functions used by GRExprEngine.
//
//===----------------------------------------------------------------------===//

#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
#include "clang/Analysis/PathSensitive/GRExprEngine.h"

using namespace clang;

void GRTransferFuncs::RegisterChecks(GRExprEngine& Eng) {}

void GRTransferFuncs::EvalStore(ExplodedNodeSet<ValueState>& Dst,
                                GRExprEngine& Eng,
                                GRStmtNodeBuilder<ValueState>& Builder,
                                Expr* E, ExplodedNode<ValueState>* Pred,
                                const ValueState* St, RVal TargetLV, RVal Val) {
  
  // This code basically matches the "safety-net" logic of GRExprEngine:
  //  bind Val to TargetLV, and create a new node.  We replicate it here
  //  because subclasses of GRTransferFuncs may wish to call it.

  assert (!TargetLV.isUndef());
  
  if (TargetLV.isUnknown())
    Builder.MakeNode(Dst, E, Pred, St);
  else
    Builder.MakeNode(Dst, E, Pred,
                Eng.getStateManager().SetRVal(St, cast<LVal>(TargetLV), Val));    
}

void GRTransferFuncs::EvalBinOpNN(ExplodedNodeSet<ValueState>& Dst,
                                  GRExprEngine& Engine,
                                  GRStmtNodeBuilder<ValueState>& Builder,
                                  BinaryOperator::Opcode Op,
                                  Expr* Ex,
                                  NonLVal L, NonLVal R,
                                  ExplodedNode<ValueState>* Pred) {

  ValueStateManager& StateMgr = Engine.getStateManager();
  const ValueState* St = Builder.GetState(Pred);
  
  RVal Result = EvalBinOp(Engine, Op, L, R);
  Builder.MakeNode(Dst, Ex, Pred, StateMgr.SetRVal(St, Ex, Result));
}