[cfe-commits] r46630 - in /cfe/trunk: Analysis/GRConstants.cpp Analysis/RValues.cpp Analysis/RValues.h test/Makefile
Ted Kremenek
kremenek at apple.com
Thu Jan 31 22:36:41 PST 2008
Author: kremenek
Date: Fri Feb 1 00:36:40 2008
New Revision: 46630
URL: http://llvm.org/viewvc/llvm-project?rev=46630&view=rev
Log:
Implemented casts for ConcreteInt and ConcreteIntLValue.
Implemented '==' and '!=' for ConcreteIntLValue.
Modified:
cfe/trunk/Analysis/GRConstants.cpp
cfe/trunk/Analysis/RValues.cpp
cfe/trunk/Analysis/RValues.h
cfe/trunk/test/Makefile
Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46630&r1=46629&r2=46630&view=diff
==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Fri Feb 1 00:36:40 2008
@@ -778,7 +778,22 @@
GRConstants::StateTy GRConstants::Assume(StateTy St, LValue Cond, bool Assumption,
bool& isFeasible) {
- return St;
+
+ switch (Cond.getSubKind()) {
+ default:
+ assert (false && "'Assume' not implemented for this NonLValue.");
+ return St;
+
+ case LValueDeclKind:
+ isFeasible = Assumption;
+ return St;
+
+ case ConcreteIntLValueKind: {
+ bool b = cast<ConcreteIntLValue>(Cond).getValue() != 0;
+ isFeasible = b ? Assumption : !Assumption;
+ return St;
+ }
+ }
}
GRConstants::StateTy GRConstants::Assume(StateTy St, NonLValue Cond, bool Assumption,
Modified: cfe/trunk/Analysis/RValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.cpp?rev=46630&r1=46629&r2=46630&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.cpp (original)
+++ cfe/trunk/Analysis/RValues.cpp Fri Feb 1 00:36:40 2008
@@ -79,20 +79,56 @@
return getValue(V);
}
-
//===----------------------------------------------------------------------===//
-// Transfer function dispatch for Non-LValues.
+// Transfer function for Casts.
//===----------------------------------------------------------------------===//
RValue RValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const {
- switch (getSubKind()) {
- case ConcreteIntKind:
- return cast<ConcreteInt>(this)->Cast(ValMgr, CastExpr);
- default:
- return InvalidValue();
+ switch (getBaseKind()) {
+ default: assert(false && "Invalid RValue."); break;
+ case LValueKind: return cast<LValue>(this)->Cast(ValMgr, CastExpr);
+ case NonLValueKind: return cast<NonLValue>(this)->Cast(ValMgr, CastExpr);
+ case UninitializedKind: case InvalidKind: break;
}
+
+ return *this;
+}
+
+RValue LValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const {
+ if (CastExpr->getType()->isPointerType())
+ return *this;
+
+ assert (CastExpr->getType()->isIntegerType());
+
+ if (!isa<ConcreteIntLValue>(*this))
+ return InvalidValue();
+
+ APSInt V = cast<ConcreteIntLValue>(this)->getValue();
+ QualType T = CastExpr->getType();
+ V.setIsUnsigned(T->isUnsignedIntegerType());
+ V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
+ return ConcreteInt(ValMgr.getValue(V));
}
+RValue NonLValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const {
+ if (!isa<ConcreteInt>(this))
+ return InvalidValue();
+
+ APSInt V = cast<ConcreteInt>(this)->getValue();
+ QualType T = CastExpr->getType();
+ V.setIsUnsigned(T->isUnsignedIntegerType());
+ V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart()));
+
+ if (CastExpr->getType()->isPointerType())
+ return ConcreteIntLValue(ValMgr.getValue(V));
+ else
+ return ConcreteInt(ValMgr.getValue(V));
+}
+
+//===----------------------------------------------------------------------===//
+// Transfer function dispatch for Non-LValues.
+//===----------------------------------------------------------------------===//
+
NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const {
switch (getSubKind()) {
case ConcreteIntKind:
@@ -162,6 +198,13 @@
default:
assert(false && "EQ not implemented for this LValue.");
return cast<NonLValue>(InvalidValue());
+
+ case ConcreteIntLValueKind: {
+ bool b = cast<ConcreteIntLValue>(this)->getValue() ==
+ cast<ConcreteIntLValue>(RHS).getValue();
+
+ return NonLValue::GetIntTruthValue(ValMgr, b);
+ }
case LValueDeclKind: {
bool b = cast<LValueDecl>(*this) == cast<LValueDecl>(RHS);
@@ -179,6 +222,13 @@
assert(false && "EQ not implemented for this LValue.");
return cast<NonLValue>(InvalidValue());
+ case ConcreteIntLValueKind: {
+ bool b = cast<ConcreteIntLValue>(this)->getValue() !=
+ cast<ConcreteIntLValue>(RHS).getValue();
+
+ return NonLValue::GetIntTruthValue(ValMgr, b);
+ }
+
case LValueDeclKind: {
bool b = cast<LValueDecl>(*this) != cast<LValueDecl>(RHS);
return NonLValue::GetIntTruthValue(ValMgr, b);
@@ -255,7 +305,12 @@
}
void LValue::print(std::ostream& Out) const {
- switch (getSubKind()) {
+ switch (getSubKind()) {
+ case ConcreteIntLValueKind:
+ Out << cast<ConcreteIntLValue>(this)->getValue().toString()
+ << " (LValue)";
+ break;
+
case SymbolicLValueKind:
Out << '$' << cast<SymbolicLValue>(this)->getSymbolID();
break;
Modified: cfe/trunk/Analysis/RValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.h?rev=46630&r1=46629&r2=46630&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.h (original)
+++ cfe/trunk/Analysis/RValues.h Fri Feb 1 00:36:40 2008
@@ -187,6 +187,8 @@
public:
void print(std::ostream& Out) const;
+ RValue Cast(ValueManager& ValMgr, Expr* CastExpr) const;
+
// Arithmetic operators.
NonLValue Add(ValueManager& ValMgr, const NonLValue& RHS) const;
NonLValue Sub(ValueManager& ValMgr, const NonLValue& RHS) const;
@@ -199,6 +201,7 @@
NonLValue EQ(ValueManager& ValMgr, const NonLValue& RHS) const;
NonLValue NE(ValueManager& ValMgr, const NonLValue& RHS) const;
+
// Utility methods to create NonLValues.
static NonLValue GetValue(ValueManager& ValMgr, uint64_t X, QualType T,
SourceLocation Loc = SourceLocation());
@@ -223,6 +226,8 @@
public:
void print(std::ostream& Out) const;
+ RValue Cast(ValueManager& ValMgr, Expr* CastExpr) const;
+
// Equality operators.
NonLValue EQ(ValueManager& ValMgr, const LValue& RHS) const;
NonLValue NE(ValueManager& ValMgr, const LValue& RHS) const;
@@ -237,8 +242,7 @@
// Subclasses of NonLValue.
//==------------------------------------------------------------------------==//
-enum NonLValueKind { SymbolicNonLValueKind, ConcreteIntKind,
-NumNonLValueKind };
+enum NonLValueKind { SymbolicNonLValueKind, ConcreteIntKind, NumNonLValueKind };
class SymbolicNonLValue : public NonLValue {
public:
@@ -326,9 +330,9 @@
// Subclasses of LValue.
//==------------------------------------------------------------------------==//
-enum LValueKind { SymbolicLValueKind, LValueDeclKind,
-ConcreteIntLValueKind, NumLValueKind };
-
+enum LValueKind { SymbolicLValueKind, LValueDeclKind, ConcreteIntLValueKind,
+ NumLValueKind };
+
class SymbolicLValue : public LValue {
public:
SymbolicLValue(unsigned SymID)
Modified: cfe/trunk/test/Makefile
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Makefile?rev=46630&r1=46629&r2=46630&view=diff
==============================================================================
--- cfe/trunk/test/Makefile (original)
+++ cfe/trunk/test/Makefile Fri Feb 1 00:36:40 2008
@@ -3,6 +3,6 @@
all::
PATH=$$PATH:$(ToolDir):$(LLVM_SRC_ROOT)/test/Scripts find\
- CodeGen Lexer Preprocessor Parser Sema Analysis Serialization\
+ Lexer Preprocessor Parser Sema Analysis Serialization\
\( -name '*.c' -or -name '*.cpp' -or -name '*.m' \)\
-print -exec ./TestRunner.sh {} \;
More information about the cfe-commits
mailing list