Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 77a301f

Browse files
committed
Use unique_ptr to handle ownership of GCOVFunctions in GCOVProfiler.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206786 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 864c531 commit 77a301f

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

lib/Transforms/Instrumentation/GCOVProfiling.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/Support/raw_ostream.h"
4040
#include "llvm/Transforms/Utils/ModuleUtils.h"
4141
#include <algorithm>
42+
#include <memory>
4243
#include <string>
4344
#include <utility>
4445
using namespace llvm;
@@ -77,9 +78,6 @@ namespace {
7778
"GCOVProfiler asked to do nothing?");
7879
init();
7980
}
80-
~GCOVProfiler() {
81-
DeleteContainerPointers(Funcs);
82-
}
8381
const char *getPassName() const override {
8482
return "GCOV Profiler";
8583
}
@@ -141,7 +139,7 @@ namespace {
141139

142140
Module *M;
143141
LLVMContext *Ctx;
144-
SmallVector<GCOVFunction *, 16> Funcs;
142+
SmallVector<std::unique_ptr<GCOVFunction>, 16> Funcs;
145143
};
146144
}
147145

@@ -499,19 +497,19 @@ void GCOVProfiler::emitProfileNotes() {
499497
++It;
500498
EntryBlock.splitBasicBlock(It);
501499

502-
GCOVFunction *Func =
503-
new GCOVFunction(SP, &out, i, Options.UseCfgChecksum);
504-
Funcs.push_back(Func);
500+
Funcs.push_back(
501+
make_unique<GCOVFunction>(SP, &out, i, Options.UseCfgChecksum));
502+
GCOVFunction &Func = *Funcs.back();
505503

506504
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
507-
GCOVBlock &Block = Func->getBlock(BB);
505+
GCOVBlock &Block = Func.getBlock(BB);
508506
TerminatorInst *TI = BB->getTerminator();
509507
if (int successors = TI->getNumSuccessors()) {
510508
for (int i = 0; i != successors; ++i) {
511-
Block.addEdge(Func->getBlock(TI->getSuccessor(i)));
509+
Block.addEdge(Func.getBlock(TI->getSuccessor(i)));
512510
}
513511
} else if (isa<ReturnInst>(TI)) {
514-
Block.addEdge(Func->getReturnBlock());
512+
Block.addEdge(Func.getReturnBlock());
515513
}
516514

517515
uint32_t Line = 0;
@@ -527,17 +525,15 @@ void GCOVProfiler::emitProfileNotes() {
527525
Lines.addLine(Loc.getLine());
528526
}
529527
}
530-
EdgeDestinations += Func->getEdgeDestinations();
528+
EdgeDestinations += Func.getEdgeDestinations();
531529
}
532530

533531
FileChecksums.push_back(hash_value(EdgeDestinations));
534532
out.write("oncg", 4);
535533
out.write(ReversedVersion, 4);
536534
out.write(reinterpret_cast<char*>(&FileChecksums.back()), 4);
537535

538-
for (SmallVectorImpl<GCOVFunction *>::iterator I = Funcs.begin(),
539-
E = Funcs.end(); I != E; ++I) {
540-
GCOVFunction *Func = *I;
536+
for (auto &Func : Funcs) {
541537
Func->setCfgChecksum(FileChecksums.back());
542538
Func->writeOut();
543539
}

0 commit comments

Comments
 (0)