[PATCH] Code de-duplication in Consumed analysis

Aaron Ballman aaron.ballman at gmail.com
Tue Oct 22 16:34:48 PDT 2013


Patch LGTM!

~Aaron

On Tue, Oct 22, 2013 at 6:41 PM, Chris Wailes <chris.wailes at gmail.com> wrote:
> 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) {



More information about the cfe-commits mailing list