[cfe-commits] r46835 - in /cfe/trunk/Analysis: GRConstants.cpp RValues.cpp RValues.h ValueState.cpp
Ted Kremenek
kremenek at apple.com
Wed Feb 6 17:08:27 PST 2008
Author: kremenek
Date: Wed Feb 6 19:08:27 2008
New Revision: 46835
URL: http://llvm.org/viewvc/llvm-project?rev=46835&view=rev
Log:
Added transfer function logic for ReturnStmts.
Fixed insidious bug in handling dereferences.
Modified:
cfe/trunk/Analysis/GRConstants.cpp
cfe/trunk/Analysis/RValues.cpp
cfe/trunk/Analysis/RValues.h
cfe/trunk/Analysis/ValueState.cpp
Modified: cfe/trunk/Analysis/GRConstants.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/GRConstants.cpp?rev=46835&r1=46834&r2=46835&view=diff
==============================================================================
--- cfe/trunk/Analysis/GRConstants.cpp (original)
+++ cfe/trunk/Analysis/GRConstants.cpp Wed Feb 6 19:08:27 2008
@@ -256,6 +256,8 @@
/// VisitBinaryOperator - Transfer function logic for binary operators.
void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst);
+ void VisitAssignmentLHS(Expr* E, NodeTy* Pred, NodeSet& Dst);
+
/// VisitDeclStmt - Transfer function logic for DeclStmts.
void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst);
@@ -671,7 +673,7 @@
}
case UnaryOperator::Deref: {
- const LValue& L1 = GetLValue(St, U->getSubExpr());
+ const LValue& L1 = cast<LValue>(GetValue(St, U->getSubExpr()));
Nodify(Dst, U, N1, SetValue(St, U, GetValue(St, L1)));
break;
}
@@ -682,11 +684,31 @@
}
}
+void GRConstants::VisitAssignmentLHS(Expr* E, GRConstants::NodeTy* Pred,
+ GRConstants::NodeSet& Dst) {
+
+ if (isa<DeclRefExpr>(E))
+ return;
+
+ if (UnaryOperator* U = dyn_cast<UnaryOperator>(E)) {
+ if (U->getOpcode() == UnaryOperator::Deref) {
+ Visit(U->getSubExpr(), Pred, Dst);
+ return;
+ }
+ }
+
+ Visit(E, Pred, Dst);
+}
+
void GRConstants::VisitBinaryOperator(BinaryOperator* B,
GRConstants::NodeTy* Pred,
GRConstants::NodeSet& Dst) {
NodeSet S1;
- Visit(B->getLHS(), Pred, S1);
+
+ if (B->isAssignmentOp())
+ VisitAssignmentLHS(B->getLHS(), Pred, S1);
+ else
+ Visit(B->getLHS(), Pred, S1);
for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
NodeTy* N1 = *I1;
@@ -712,6 +734,11 @@
if (Op <= BinaryOperator::Or) {
+ if (isa<InvalidValue>(V1) || isa<UninitializedValue>(V1)) {
+ Nodify(Dst, B, N2, SetValue(St, B, V1));
+ continue;
+ }
+
if (isa<LValue>(V1)) {
// FIXME: Add support for RHS being a non-lvalue.
const LValue& L1 = cast<LValue>(V1);
@@ -824,6 +851,14 @@
break;
}
+ case Stmt::ReturnStmtClass:
+ if (Expr* R = cast<ReturnStmt>(S)->getRetValue())
+ Visit(R, Pred, Dst);
+ else
+ Dst.Add(Pred);
+
+ break;
+
case Stmt::DeclStmtClass:
VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst);
break;
Modified: cfe/trunk/Analysis/RValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.cpp?rev=46835&r1=46834&r2=46835&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.cpp (original)
+++ cfe/trunk/Analysis/RValues.cpp Wed Feb 6 19:08:27 2008
@@ -481,7 +481,9 @@
return nonlval::SymbolVal(SymMgr.getSymbol(D));
}
-
+void RValue::print() const {
+ print(*llvm::cerr.stream());
+}
//===----------------------------------------------------------------------===//
// Pretty-Printing.
Modified: cfe/trunk/Analysis/RValues.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/RValues.h?rev=46835&r1=46834&r2=46835&view=diff
==============================================================================
--- cfe/trunk/Analysis/RValues.h (original)
+++ cfe/trunk/Analysis/RValues.h Wed Feb 6 19:08:27 2008
@@ -260,7 +260,7 @@
inline bool isInvalid() const { return getRawKind() == InvalidKind; }
void print(std::ostream& OS) const;
- void print() const { print(*llvm::cerr.stream()); }
+ void print() const;
// Implement isa<T> support.
static inline bool classof(const RValue*) { return true; }
@@ -323,7 +323,7 @@
NonLValue NE(ValueManager& ValMgr, const LValue& RHS) const;
public:
- void print(std::ostream& Out) const;
+// void print(std::ostream& Out) const;
RValue EvalBinaryOp(ValueManager& ValMgr, BinaryOperator::Opcode Op,
const LValue& RHS) const;
Modified: cfe/trunk/Analysis/ValueState.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Analysis/ValueState.cpp?rev=46835&r1=46834&r2=46835&view=diff
==============================================================================
--- cfe/trunk/Analysis/ValueState.cpp (original)
+++ cfe/trunk/Analysis/ValueState.cpp Wed Feb 6 19:08:27 2008
@@ -155,6 +155,10 @@
if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S))
return lval::DeclVal(DR->getDecl());
+ if (UnaryOperator* U = dyn_cast<UnaryOperator>(S))
+ if (U->getOpcode() == UnaryOperator::Deref)
+ return cast<LValue>(GetValue(St, U->getSubExpr()));
+
return cast<LValue>(GetValue(St, S));
}
More information about the cfe-commits
mailing list