[PATCH] Code de-duplication in Consumed analysis
Chris Wailes
chris.wailes at gmail.com
Tue Oct 22 15:41:38 PDT 2013
Hi dblaikie, delesley, aaron.ballman,
Several locations in Consumed.cpp duplicated the functionality of the forwardInfo function. The code was replaced with a call to forwardInfo.
A test was also added to make sure that an invalid pointer wasn't dereferenced.
http://llvm-reviews.chandlerc.com/D2002
Files:
lib/Analysis/Consumed.cpp
Index: lib/Analysis/Consumed.cpp
===================================================================
--- lib/Analysis/Consumed.cpp
+++ lib/Analysis/Consumed.cpp
@@ -592,12 +592,7 @@
// Special case for the std::move function.
// TODO: Make this more specific. (Deferred)
if (FunDecl->getNameAsString() == "move") {
- InfoEntry Entry = PropagationMap.find(Call->getArg(0));
-
- if (Entry != PropagationMap.end()) {
- PropagationMap.insert(PairType(Call, Entry->second));
- }
-
+ forwardInfo(Call->getArg(0), Call);
return;
}
@@ -690,26 +685,25 @@
} else if (Constructor->isMoveConstructor()) {
- PropagationInfo PInfo =
- PropagationMap.find(Call->getArg(0))->second;
+ InfoEntry Entry = PropagationMap.find(Call->getArg(0));
- if (PInfo.isVar()) {
- const VarDecl* Var = PInfo.getVar();
-
- PropagationMap.insert(PairType(Call,
- PropagationInfo(StateMap->getState(Var), ThisType)));
-
- StateMap->setState(Var, consumed::CS_Consumed);
+ if (Entry != PropagationMap.end()) {
+ PropagationInfo PInfo = Entry->second;
- } else {
- PropagationMap.insert(PairType(Call, PInfo));
+ if (PInfo.isVar()) {
+ const VarDecl* Var = PInfo.getVar();
+
+ PropagationMap.insert(PairType(Call,
+ PropagationInfo(StateMap->getState(Var), ThisType)));
+
+ StateMap->setState(Var, consumed::CS_Consumed);
+
+ } else {
+ PropagationMap.insert(PairType(Call, PInfo));
+ }
}
-
} else if (Constructor->isCopyConstructor()) {
- MapType::iterator Entry = PropagationMap.find(Call->getArg(0));
-
- if (Entry != PropagationMap.end())
- PropagationMap.insert(PairType(Call, Entry->second));
+ forwardInfo(Call->getArg(0), Call);
} else {
ConsumedState RetState = mapConsumableAttrState(ThisType);
@@ -717,7 +711,6 @@
}
}
-
void ConsumedStmtVisitor::VisitCXXMemberCallExpr(
const CXXMemberCallExpr *Call) {
@@ -854,10 +847,7 @@
void ConsumedStmtVisitor::VisitMaterializeTemporaryExpr(
const MaterializeTemporaryExpr *Temp) {
- InfoEntry Entry = PropagationMap.find(Temp->GetTemporaryExpr());
-
- if (Entry != PropagationMap.end())
- PropagationMap.insert(PairType(Temp, Entry->second));
+ forwardInfo(Temp->GetTemporaryExpr(), Temp);
}
void ConsumedStmtVisitor::VisitMemberExpr(const MemberExpr *MExpr) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2002.1.patch
Type: text/x-patch
Size: 2495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131022/7b75d22b/attachment.bin>
More information about the cfe-commits
mailing list