Consumed analysis: fix assert failure.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@193010 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/Consumed.cpp b/lib/Analysis/Consumed.cpp
index 8358b6b..ed806ce 100644
--- a/lib/Analysis/Consumed.cpp
+++ b/lib/Analysis/Consumed.cpp
@@ -414,6 +414,15 @@
void propagateReturnType(const Stmt *Call, const FunctionDecl *Fun,
QualType ReturnType);
+ inline ConsumedState getPInfoState(const PropagationInfo& PInfo) {
+ if (PInfo.isVar())
+ return StateMap->getState(PInfo.getVar());
+ else if (PInfo.isState())
+ return PInfo.getState();
+ else
+ return CS_None;
+ }
+
public:
void checkCallability(const PropagationInfo &PInfo,
const FunctionDecl *FunDecl,
@@ -927,15 +936,18 @@
void ConsumedStmtVisitor::VisitVarDecl(const VarDecl *Var) {
if (isConsumableType(Var->getType())) {
if (Var->hasInit()) {
- PropagationInfo PInfo =
- PropagationMap.find(Var->getInit())->second;
-
- StateMap->setState(Var, PInfo.isVar() ?
- StateMap->getState(PInfo.getVar()) : PInfo.getState());
-
- } else {
- StateMap->setState(Var, consumed::CS_Unknown);
+ MapType::iterator VIT = PropagationMap.find(Var->getInit());
+ if (VIT != PropagationMap.end()) {
+ PropagationInfo PInfo = VIT->second;
+ ConsumedState St = getPInfoState(PInfo);
+ if (St != consumed::CS_None) {
+ StateMap->setState(Var, St);
+ return;
+ }
+ }
}
+ // Otherwise
+ StateMap->setState(Var, consumed::CS_Unknown);
}
}
}} // end clang::consumed::ConsumedStmtVisitor