Skip to content
Snippets Groups Projects
Commit b5339121 authored by Ted Kremenek's avatar Ted Kremenek
Browse files

Added special handling for UninitializedVals for the transfer function logic

for pointer dereferences.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47340 91177308-0d34-0410-b5e6-96231b3b80d8
parent a888c98b
No related branches found
No related tags found
No related merge requests found
...@@ -642,6 +642,17 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U, ...@@ -642,6 +642,17 @@ void GRExprEngine::VisitUnaryOperator(UnaryOperator* U,
const RValue& V = GetValue(St, U->getSubExpr()); const RValue& V = GetValue(St, U->getSubExpr());
const LValue& L1 = cast<LValue>(V); const LValue& L1 = cast<LValue>(V);
if (isa<UninitializedVal>(L1)) {
NodeTy* N = Builder->generateNode(U, St, N1);
if (N) {
N->markAsSink();
UninitDeref.insert(N);
}
return;
}
// After a dereference, one of two possible situations arise: // After a dereference, one of two possible situations arise:
// (1) A crash, because the pointer was NULL. // (1) A crash, because the pointer was NULL.
// (2) The pointer is not NULL, and the dereference works. // (2) The pointer is not NULL, and the dereference works.
...@@ -776,6 +787,11 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, ...@@ -776,6 +787,11 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B,
break; break;
} }
if (isa<UninitializedVal>(V2)) {
Nodify(Dst, B, N2, SetValue(SetValue(St, B, V2), L1, V2));
break;
}
RValue Result = cast<NonLValue>(UnknownVal()); RValue Result = cast<NonLValue>(UnknownVal());
if (Op >= BinaryOperator::AndAssign) if (Op >= BinaryOperator::AndAssign)
...@@ -1232,6 +1248,7 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> : ...@@ -1232,6 +1248,7 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> :
if (GraphPrintCheckerState->isImplicitNullDeref(N) || if (GraphPrintCheckerState->isImplicitNullDeref(N) ||
GraphPrintCheckerState->isExplicitNullDeref(N) || GraphPrintCheckerState->isExplicitNullDeref(N) ||
GraphPrintCheckerState->isUninitDeref(N) ||
GraphPrintCheckerState->isUninitStore(N) || GraphPrintCheckerState->isUninitStore(N) ||
GraphPrintCheckerState->isUninitControlFlow(N)) GraphPrintCheckerState->isUninitControlFlow(N))
return "color=\"red\",style=\"filled\""; return "color=\"red\",style=\"filled\"";
...@@ -1268,6 +1285,9 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> : ...@@ -1268,6 +1285,9 @@ struct VISIBILITY_HIDDEN DOTGraphTraits<GRExprEngine::NodeTy*> :
else if (GraphPrintCheckerState->isExplicitNullDeref(N)) { else if (GraphPrintCheckerState->isExplicitNullDeref(N)) {
Out << "\\|Explicit-Null Dereference.\\l"; Out << "\\|Explicit-Null Dereference.\\l";
} }
else if (GraphPrintCheckerState->isUninitDeref(N)) {
Out << "\\|Dereference of uninitialied value.\\l";
}
else if (GraphPrintCheckerState->isUninitStore(N)) { else if (GraphPrintCheckerState->isUninitStore(N)) {
Out << "\\|Store to Uninitialized LValue."; Out << "\\|Store to Uninitialized LValue.";
} }
......
...@@ -121,9 +121,10 @@ protected: ...@@ -121,9 +121,10 @@ protected:
/// ImplicitNullDeref - Nodes in the ExplodedGraph that result from /// ImplicitNullDeref - Nodes in the ExplodedGraph that result from
/// taking a dereference on a symbolic pointer that may be NULL. /// taking a dereference on a symbolic pointer that may be NULL.
typedef llvm::SmallPtrSet<NodeTy*,5> NullDerefTy; typedef llvm::SmallPtrSet<NodeTy*,5> BadDerefTy;
NullDerefTy ImplicitNullDeref; BadDerefTy ImplicitNullDeref;
NullDerefTy ExplicitNullDeref; BadDerefTy ExplicitNullDeref;
BadDerefTy UninitDeref;
bool StateCleaned; bool StateCleaned;
...@@ -187,7 +188,11 @@ public: ...@@ -187,7 +188,11 @@ public:
return N->isSink() && ExplicitNullDeref.count(const_cast<NodeTy*>(N)) != 0; return N->isSink() && ExplicitNullDeref.count(const_cast<NodeTy*>(N)) != 0;
} }
typedef NullDerefTy::iterator null_iterator; bool isUninitDeref(const NodeTy* N) const {
return N->isSink() && UninitDeref.count(const_cast<NodeTy*>(N)) != 0;
}
typedef BadDerefTy::iterator null_iterator;
null_iterator null_begin() { return ExplicitNullDeref.begin(); } null_iterator null_begin() { return ExplicitNullDeref.begin(); }
null_iterator null_end() { return ExplicitNullDeref.end(); } null_iterator null_end() { return ExplicitNullDeref.end(); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment