mirror of
https://github.com/RPCS3/llvm.git
synced 2024-11-28 14:10:55 +00:00
Have Module::createRNG return a unique_ptr
Instead of a raw pointer, this makes memory management safer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307762 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1f56665b90
commit
fbec1c990e
@ -249,7 +249,7 @@ public:
|
||||
/// when other randomness consuming passes are added or removed. In
|
||||
/// addition, the random stream will be reproducible across LLVM
|
||||
/// versions when the pass does not change.
|
||||
RandomNumberGenerator *createRNG(const Pass* P) const;
|
||||
std::unique_ptr<RandomNumberGenerator> createRNG(const Pass* P) const;
|
||||
|
||||
/// @}
|
||||
/// @name Module Level Mutators
|
||||
|
@ -88,7 +88,7 @@ Module::~Module() {
|
||||
delete static_cast<StringMap<NamedMDNode *> *>(NamedMDSymTab);
|
||||
}
|
||||
|
||||
RandomNumberGenerator *Module::createRNG(const Pass* P) const {
|
||||
std::unique_ptr<RandomNumberGenerator> Module::createRNG(const Pass* P) const {
|
||||
SmallString<32> Salt(P->getPassName());
|
||||
|
||||
// This RNG is guaranteed to produce the same random stream only
|
||||
@ -103,7 +103,7 @@ RandomNumberGenerator *Module::createRNG(const Pass* P) const {
|
||||
// store salt metadata from the Module constructor.
|
||||
Salt += sys::path::filename(getModuleIdentifier());
|
||||
|
||||
return new RandomNumberGenerator(Salt);
|
||||
return std::unique_ptr<RandomNumberGenerator>{new RandomNumberGenerator(Salt)};
|
||||
}
|
||||
|
||||
/// getNamedValue - Return the first global value in the module with
|
||||
|
@ -63,7 +63,7 @@ TEST(ModuleTest, randomNumberGenerator) {
|
||||
|
||||
std::array<int, NBCheck> RandomStreams[2];
|
||||
for (auto &RandomStream : RandomStreams) {
|
||||
std::unique_ptr<RandomNumberGenerator> RNG{M.createRNG(&DP)};
|
||||
std::unique_ptr<RandomNumberGenerator> RNG = M.createRNG(&DP);
|
||||
std::generate(RandomStream.begin(), RandomStream.end(),
|
||||
[&]() { return dist(*RNG); });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user