[PATCH] unique_ptrify llvm::getLazyBitcodeModule's MemoryBuffer parameter

Sean Silva chisophugis at gmail.com
Tue Aug 12 16:49:15 PDT 2014


Maybe this is worth another thread on LLVMDev, but I really dislike using unique_ptr when it complicates things. I see unique_ptr as a lightweight way ensure things are correct by default with no need to fiddle around; it should bring an immediate sense of security. Needing to have comments about ownership in code using unique_ptr defeats the purpose IMO.

I feel like this patch is really complicating things, trying to move towards unique_ptr just for the sake of using unique_ptr. There's no difference between a unique_ptr that needs to have careful comments about ownership around it vs. a raw pointer with careful comments about ownership, besides the possibility that the unique_ptr will possibly lure the reader into a false sense of security.

An unused-result call to .release() is as bad as raw new/delete: it is a manual, error-prone intervention for controlling an object's lifetime.

================
Comment at: lib/Bitcode/Reader/BitcodeReader.cpp:3552-3554
@@ -3551,1 +3551,5 @@
+ErrorOr<Module *>
+llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
+                           LLVMContext &Context) {
+  return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false);
 }
----------------
What's the point of this? All std::move does is cast to T&&. You already have a T&&.

http://reviews.llvm.org/D4876






More information about the llvm-commits mailing list