blob: 447eb44f0e2b96d8f1cd2ae67bead48e48e243e9 [file] [log] [blame]
Ted Kremenekd59cccc2008-02-14 18:28:23 +00001// GRSimpleVals.cpp - Transfer functions for tracking simple values -*- 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 files defines GRSimpleVals, a sub-class of GRTransferFuncs that
11// provides transfer functions for performing simple value tracking with
12// limited support for symbolics.
13//
14//===----------------------------------------------------------------------===//
15
16#include "GRSimpleVals.h"
17
18using namespace clang;
19
20//===----------------------------------------------------------------------===//
21// Transfer function for Casts.
22//===----------------------------------------------------------------------===//
23
24RValue GRSimpleVals::EvalCast(ValueManager& ValMgr, NonLValue X,
25 Expr* CastExpr) {
26
27 if (!isa<nonlval::ConcreteInt>(X))
28 return UnknownVal();
29
30 llvm::APSInt V = cast<nonlval::ConcreteInt>(X).getValue();
31 QualType T = CastExpr->getType();
32 V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType());
33 V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
34
35 if (CastExpr->getType()->isPointerType())
36 return lval::ConcreteInt(ValMgr.getValue(V));
37 else
38 return nonlval::ConcreteInt(ValMgr.getValue(V));
39}
40
41// Casts.
42
43RValue GRSimpleVals::EvalCast(ValueManager& ValMgr, LValue X, Expr* CastExpr) {
44
45 if (CastExpr->getType()->isPointerType())
46 return X;
47
48 assert (CastExpr->getType()->isIntegerType());
49
50 if (!isa<lval::ConcreteInt>(X))
51 return UnknownVal();
52
53 llvm::APSInt V = cast<lval::ConcreteInt>(X).getValue();
54 QualType T = CastExpr->getType();
55 V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType());
56 V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
57
58 return nonlval::ConcreteInt(ValMgr.getValue(V));
59}