Instead of a raw pointer, this makes memory management safer.
llvm-svn: 307762
/// 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
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
// 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
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); });
}