[PATCH] Memory management cleanup in Consumed.cpp
Aaron Ballman
aaron.ballman at gmail.com
Thu Oct 24 08:06:20 PDT 2013
LGTM, thanks!
~Aaron
On Thu, Oct 24, 2013 at 11:05 AM, Chris Wailes <chris.wailes at gmail.com> wrote:
> Hi delesley, dblaikie, aaron.ballman,
>
> Used an OwningPtr to clean up some memory management code in Consumed.cpp.
>
> http://llvm-reviews.chandlerc.com/D2016
>
> Files:
> lib/Analysis/Consumed.cpp
>
> Index: lib/Analysis/Consumed.cpp
> ===================================================================
> --- lib/Analysis/Consumed.cpp
> +++ lib/Analysis/Consumed.cpp
> @@ -27,6 +27,7 @@
> #include "clang/Basic/OperatorKinds.h"
> #include "clang/Basic/SourceLocation.h"
> #include "llvm/ADT/DenseMap.h"
> +#include "llvm/ADT/OwningPtr.h"
> #include "llvm/ADT/SmallVector.h"
> #include "llvm/Support/Compiler.h"
> #include "llvm/Support/raw_ostream.h"
> @@ -1259,7 +1260,7 @@
> bool ConsumedAnalyzer::splitState(const CFGBlock *CurrBlock,
> const ConsumedStmtVisitor &Visitor) {
>
> - ConsumedStateMap *FalseStates = new ConsumedStateMap(*CurrStates);
> + OwningPtr<ConsumedStateMap> FalseStates(new ConsumedStateMap(*CurrStates));
> PropagationInfo PInfo;
>
> if (const IfStmt *IfNode =
> @@ -1274,15 +1275,15 @@
> if (PInfo.isTest()) {
> CurrStates->setSource(Cond);
> FalseStates->setSource(Cond);
> - splitVarStateForIf(IfNode, PInfo.getTest(), CurrStates, FalseStates);
> + splitVarStateForIf(IfNode, PInfo.getTest(), CurrStates,
> + FalseStates.get());
>
> } else if (PInfo.isBinTest()) {
> CurrStates->setSource(PInfo.testSourceNode());
> FalseStates->setSource(PInfo.testSourceNode());
> - splitVarStateForIfBinOp(PInfo, CurrStates, FalseStates);
> + splitVarStateForIfBinOp(PInfo, CurrStates, FalseStates.get());
>
> } else {
> - delete FalseStates;
> return false;
> }
>
> @@ -1294,13 +1295,10 @@
> if ((BinOp = dyn_cast_or_null<BinaryOperator>(BinOp->getLHS()))) {
> PInfo = Visitor.getInfo(BinOp->getRHS());
>
> - if (!PInfo.isTest()) {
> - delete FalseStates;
> + if (!PInfo.isTest())
> return false;
> - }
>
> } else {
> - delete FalseStates;
> return false;
> }
> }
> @@ -1326,7 +1324,6 @@
> }
>
> } else {
> - delete FalseStates;
> return false;
> }
>
> @@ -1338,9 +1335,7 @@
> delete CurrStates;
>
> if (*++SI)
> - BlockInfo.addInfo(*SI, FalseStates);
> - else
> - delete FalseStates;
> + BlockInfo.addInfo(*SI, FalseStates.take());
>
> CurrStates = NULL;
> return true;
More information about the cfe-commits
mailing list