Started partitioning of transfer function logic (and thus the policy behind
these operations) into GRTransferFuncs and its subclasses. Originally all
of this logic was handled by the class RValue, but in reality different
analyses will want more flexibility on how they evaluate different values.
Transfer functions migrated so far: "Cast"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47125 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/GRSimpleVals.cpp b/Analysis/GRSimpleVals.cpp
new file mode 100644
index 0000000..447eb44
--- /dev/null
+++ b/Analysis/GRSimpleVals.cpp
@@ -0,0 +1,59 @@
+// GRSimpleVals.cpp - Transfer functions for tracking simple values -*- C++ -*--
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This files defines GRSimpleVals, a sub-class of GRTransferFuncs that
+// provides transfer functions for performing simple value tracking with
+// limited support for symbolics.
+//
+//===----------------------------------------------------------------------===//
+
+#include "GRSimpleVals.h"
+
+using namespace clang;
+
+//===----------------------------------------------------------------------===//
+// Transfer function for Casts.
+//===----------------------------------------------------------------------===//
+
+RValue GRSimpleVals::EvalCast(ValueManager& ValMgr, NonLValue X,
+ Expr* CastExpr) {
+
+ if (!isa<nonlval::ConcreteInt>(X))
+ return UnknownVal();
+
+ llvm::APSInt V = cast<nonlval::ConcreteInt>(X).getValue();
+ QualType T = CastExpr->getType();
+ V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType());
+ V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
+
+ if (CastExpr->getType()->isPointerType())
+ return lval::ConcreteInt(ValMgr.getValue(V));
+ else
+ return nonlval::ConcreteInt(ValMgr.getValue(V));
+}
+
+// Casts.
+
+RValue GRSimpleVals::EvalCast(ValueManager& ValMgr, LValue X, Expr* CastExpr) {
+
+ if (CastExpr->getType()->isPointerType())
+ return X;
+
+ assert (CastExpr->getType()->isIntegerType());
+
+ if (!isa<lval::ConcreteInt>(X))
+ return UnknownVal();
+
+ llvm::APSInt V = cast<lval::ConcreteInt>(X).getValue();
+ QualType T = CastExpr->getType();
+ V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType());
+ V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
+
+ return nonlval::ConcreteInt(ValMgr.getValue(V));
+}
\ No newline at end of file