From fbec1c990e883e2a37ee65537b0a775bab443db5 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Wed, 12 Jul 2017 08:03:44 +0000 Subject: [PATCH] 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 --- include/llvm/IR/Module.h | 2 +- lib/IR/Module.cpp | 4 ++-- unittests/IR/ModuleTest.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index d47d82a57bf..196e32e3615 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -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 createRNG(const Pass* P) const; /// @} /// @name Module Level Mutators diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index f8853ed169c..fdc7de6eaa3 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -88,7 +88,7 @@ Module::~Module() { delete static_cast *>(NamedMDSymTab); } -RandomNumberGenerator *Module::createRNG(const Pass* P) const { +std::unique_ptr 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{new RandomNumberGenerator(Salt)}; } /// getNamedValue - Return the first global value in the module with diff --git a/unittests/IR/ModuleTest.cpp b/unittests/IR/ModuleTest.cpp index d93d036bb11..af55a098add 100644 --- a/unittests/IR/ModuleTest.cpp +++ b/unittests/IR/ModuleTest.cpp @@ -63,7 +63,7 @@ TEST(ModuleTest, randomNumberGenerator) { std::array RandomStreams[2]; for (auto &RandomStream : RandomStreams) { - std::unique_ptr RNG{M.createRNG(&DP)}; + std::unique_ptr RNG = M.createRNG(&DP); std::generate(RandomStream.begin(), RandomStream.end(), [&]() { return dist(*RNG); }); }