Use std::make_shared in LLDB (NFC)

Unlike std::make_unique, which is only available since C++14,
std::make_shared is available since C++11. Not only is std::make_shared
a lot more readable compared to ::reset(new), it also performs a single
heap allocation for the object and control block.

Differential revision: https://reviews.llvm.org/D57990

llvm-svn: 353764
diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp
index e3332a8..1674086 100644
--- a/lldb/source/API/SBCommandInterpreter.cpp
+++ b/lldb/source/API/SBCommandInterpreter.cpp
@@ -25,6 +25,8 @@
 #include "lldb/API/SBStringList.h"
 #include "lldb/API/SBTarget.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -555,8 +557,8 @@
 lldb::SBCommand SBCommandInterpreter::AddCommand(
     const char *name, lldb::SBCommandPluginInterface *impl, const char *help) {
   lldb::CommandObjectSP new_command_sp;
-  new_command_sp.reset(new CommandPluginInterfaceImplementation(
-      *m_opaque_ptr, name, impl, help));
+  new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
+      *m_opaque_ptr, name, impl, help);
 
   if (new_command_sp &&
       m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
@@ -569,8 +571,8 @@
                                  lldb::SBCommandPluginInterface *impl,
                                  const char *help, const char *syntax) {
   lldb::CommandObjectSP new_command_sp;
-  new_command_sp.reset(new CommandPluginInterfaceImplementation(
-      *m_opaque_ptr, name, impl, help, syntax));
+  new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
+      *m_opaque_ptr, name, impl, help, syntax);
 
   if (new_command_sp &&
       m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
@@ -631,8 +633,8 @@
   if (!m_opaque_sp->IsMultiwordObject())
     return lldb::SBCommand();
   lldb::CommandObjectSP new_command_sp;
-  new_command_sp.reset(new CommandPluginInterfaceImplementation(
-      m_opaque_sp->GetCommandInterpreter(), name, impl, help));
+  new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
+      m_opaque_sp->GetCommandInterpreter(), name, impl, help);
   if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
     return lldb::SBCommand(new_command_sp);
   return lldb::SBCommand();
@@ -646,8 +648,8 @@
   if (!m_opaque_sp->IsMultiwordObject())
     return lldb::SBCommand();
   lldb::CommandObjectSP new_command_sp;
-  new_command_sp.reset(new CommandPluginInterfaceImplementation(
-      m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax));
+  new_command_sp = std::make_shared<CommandPluginInterfaceImplementation>(
+      m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax);
   if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp))
     return lldb::SBCommand(new_command_sp);
   return lldb::SBCommand();
diff --git a/lldb/source/API/SBData.cpp b/lldb/source/API/SBData.cpp
index d808ff2..54a9761 100644
--- a/lldb/source/API/SBData.cpp
+++ b/lldb/source/API/SBData.cpp
@@ -6,8 +6,6 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <inttypes.h>
-
 #include "lldb/API/SBData.h"
 #include "lldb/API/SBError.h"
 #include "lldb/API/SBStream.h"
@@ -18,6 +16,9 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Stream.h"
 
+#include <cinttypes>
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -381,7 +382,7 @@
                      lldb::ByteOrder endian, uint8_t addr_size) {
   Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(new DataExtractor(buf, size, endian, addr_size));
+    m_opaque_sp = std::make_shared<DataExtractor>(buf, size, endian, addr_size);
   else
   {
     m_opaque_sp->SetData(buf, size, endian);
@@ -530,8 +531,8 @@
   lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len));
 
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(
-        new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+    m_opaque_sp = std::make_shared<DataExtractor>(buffer_sp, GetByteOrder(),
+                                                  GetAddressByteSize());
   else
     m_opaque_sp->SetData(buffer_sp);
 
@@ -560,8 +561,8 @@
   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
 
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(
-        new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+    m_opaque_sp = std::make_shared<DataExtractor>(buffer_sp, GetByteOrder(),
+                                                  GetAddressByteSize());
   else
     m_opaque_sp->SetData(buffer_sp);
 
@@ -592,8 +593,8 @@
   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
 
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(
-        new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+    m_opaque_sp = std::make_shared<DataExtractor>(buffer_sp, GetByteOrder(),
+                                                  GetAddressByteSize());
   else
     m_opaque_sp->SetData(buffer_sp);
 
@@ -624,8 +625,8 @@
   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
 
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(
-        new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+    m_opaque_sp = std::make_shared<DataExtractor>(buffer_sp, GetByteOrder(),
+                                                  GetAddressByteSize());
   else
     m_opaque_sp->SetData(buffer_sp);
 
@@ -656,8 +657,8 @@
   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
 
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(
-        new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+    m_opaque_sp = std::make_shared<DataExtractor>(buffer_sp, GetByteOrder(),
+                                                  GetAddressByteSize());
   else
     m_opaque_sp->SetData(buffer_sp);
 
@@ -688,8 +689,8 @@
   lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len));
 
   if (!m_opaque_sp.get())
-    m_opaque_sp.reset(
-        new DataExtractor(buffer_sp, GetByteOrder(), GetAddressByteSize()));
+    m_opaque_sp = std::make_shared<DataExtractor>(buffer_sp, GetByteOrder(),
+                                                  GetAddressByteSize());
   else
     m_opaque_sp->SetData(buffer_sp);
 
diff --git a/lldb/source/API/SBInstruction.cpp b/lldb/source/API/SBInstruction.cpp
index 5b3c0aa..abc390b 100644
--- a/lldb/source/API/SBInstruction.cpp
+++ b/lldb/source/API/SBInstruction.cpp
@@ -10,6 +10,7 @@
 
 #include "lldb/API/SBAddress.h"
 #include "lldb/API/SBFrame.h"
+
 #include "lldb/API/SBInstruction.h"
 #include "lldb/API/SBStream.h"
 #include "lldb/API/SBTarget.h"
@@ -25,6 +26,8 @@
 #include "lldb/Utility/DataBufferHeap.h"
 #include "lldb/Utility/DataExtractor.h"
 
+#include <memory>
+
 //----------------------------------------------------------------------
 // We recently fixed a leak in one of the Instruction subclasses where the
 // instruction will only hold a weak reference to the disassembler to avoid a
@@ -190,7 +193,7 @@
 
 void SBInstruction::SetOpaque(const lldb::DisassemblerSP &disasm_sp,
                               const lldb::InstructionSP &inst_sp) {
-  m_opaque_sp.reset(new InstructionImpl(disasm_sp, inst_sp));
+  m_opaque_sp = std::make_shared<InstructionImpl>(disasm_sp, inst_sp);
 }
 
 bool SBInstruction::GetDescription(lldb::SBStream &s) {
diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp
index d19758b..9d4cb15 100644
--- a/lldb/source/API/SBThread.cpp
+++ b/lldb/source/API/SBThread.cpp
@@ -44,6 +44,8 @@
 #include "lldb/API/SBValue.h"
 #include "lldb/lldb-enumerations.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -290,7 +292,7 @@
 SBThreadCollection
 SBThread::GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type) {
   ThreadCollectionSP threads;
-  threads.reset(new ThreadCollection());
+  threads = std::make_shared<ThreadCollection>();
 
   std::unique_lock<std::recursive_mutex> lock;
   ExecutionContext exe_ctx(m_opaque_sp.get(), lock);
diff --git a/lldb/source/API/SBThreadPlan.cpp b/lldb/source/API/SBThreadPlan.cpp
index ba645cb..cca06df 100644
--- a/lldb/source/API/SBThreadPlan.cpp
+++ b/lldb/source/API/SBThreadPlan.cpp
@@ -41,6 +41,8 @@
 #include "lldb/API/SBThreadPlan.h"
 #include "lldb/API/SBValue.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -58,7 +60,7 @@
 SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) {
   Thread *thread = sb_thread.get();
   if (thread)
-    m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name));
+    m_opaque_sp = std::make_shared<ThreadPlanPython>(*thread, class_name);
 }
 
 //----------------------------------------------------------------------
diff --git a/lldb/source/API/SBTrace.cpp b/lldb/source/API/SBTrace.cpp
index b4e7f65..daccdec 100644
--- a/lldb/source/API/SBTrace.cpp
+++ b/lldb/source/API/SBTrace.cpp
@@ -12,6 +12,8 @@
 #include "lldb/API/SBTrace.h"
 #include "lldb/API/SBTraceOptions.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -92,7 +94,7 @@
 }
 
 SBTrace::SBTrace() {
-  m_trace_impl_sp.reset(new TraceImpl);
+  m_trace_impl_sp = std::make_shared<TraceImpl>();
   if (m_trace_impl_sp)
     m_trace_impl_sp->uid = LLDB_INVALID_UID;
 }
diff --git a/lldb/source/API/SBTraceOptions.cpp b/lldb/source/API/SBTraceOptions.cpp
index a041f74..e48f1dc 100644
--- a/lldb/source/API/SBTraceOptions.cpp
+++ b/lldb/source/API/SBTraceOptions.cpp
@@ -13,11 +13,13 @@
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/TraceOptions.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
 SBTraceOptions::SBTraceOptions() {
-  m_traceoptions_sp.reset(new TraceOptions());
+  m_traceoptions_sp = std::make_shared<TraceOptions>();
 }
 
 lldb::TraceType SBTraceOptions::getType() const {
diff --git a/lldb/source/API/SBType.cpp b/lldb/source/API/SBType.cpp
index 6f7d5c7..b67f9bc 100644
--- a/lldb/source/API/SBType.cpp
+++ b/lldb/source/API/SBType.cpp
@@ -20,6 +20,8 @@
 
 #include "llvm/ADT/APSInt.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -82,7 +84,7 @@
 
 TypeImpl &SBType::ref() {
   if (m_opaque_sp.get() == NULL)
-    m_opaque_sp.reset(new TypeImpl());
+    m_opaque_sp = std::make_shared<TypeImpl>();
   return *m_opaque_sp;
 }
 
@@ -670,7 +672,7 @@
 
 TypeMemberFunctionImpl &SBTypeMemberFunction::ref() {
   if (!m_opaque_sp)
-    m_opaque_sp.reset(new TypeMemberFunctionImpl());
+    m_opaque_sp = std::make_shared<TypeMemberFunctionImpl>();
   return *m_opaque_sp.get();
 }
 
diff --git a/lldb/source/API/SBTypeEnumMember.cpp b/lldb/source/API/SBTypeEnumMember.cpp
index 44569c3..d8b70a4 100644
--- a/lldb/source/API/SBTypeEnumMember.cpp
+++ b/lldb/source/API/SBTypeEnumMember.cpp
@@ -14,6 +14,8 @@
 #include "lldb/Symbol/Type.h"
 #include "lldb/Utility/Stream.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -28,14 +30,14 @@
     : m_opaque_sp() {
   if (this != &rhs) {
     if (rhs.IsValid())
-      m_opaque_sp.reset(new TypeEnumMemberImpl(rhs.ref()));
+      m_opaque_sp = std::make_shared<TypeEnumMemberImpl>(rhs.ref());
   }
 }
 
 SBTypeEnumMember &SBTypeEnumMember::operator=(const SBTypeEnumMember &rhs) {
   if (this != &rhs) {
     if (rhs.IsValid())
-      m_opaque_sp.reset(new TypeEnumMemberImpl(rhs.ref()));
+      m_opaque_sp = std::make_shared<TypeEnumMemberImpl>(rhs.ref());
   }
   return *this;
 }
@@ -74,7 +76,7 @@
 
 TypeEnumMemberImpl &SBTypeEnumMember::ref() {
   if (m_opaque_sp.get() == NULL)
-    m_opaque_sp.reset(new TypeEnumMemberImpl());
+    m_opaque_sp = std::make_shared<TypeEnumMemberImpl>();
   return *m_opaque_sp.get();
 }
 
diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp
index b83a4ef..439c55e 100644
--- a/lldb/source/API/SBValue.cpp
+++ b/lldb/source/API/SBValue.cpp
@@ -46,6 +46,8 @@
 #include "lldb/API/SBTarget.h"
 #include "lldb/API/SBThread.h"
 
+#include <memory>
+
 using namespace lldb;
 using namespace lldb_private;
 
@@ -485,7 +487,7 @@
   lldb::ValueObjectSP value_sp(GetSP(locker));
   TypeImplSP type_sp;
   if (value_sp) {
-    type_sp.reset(new TypeImpl(value_sp->GetTypeImpl()));
+    type_sp = std::make_shared<TypeImpl>(value_sp->GetTypeImpl());
     sb_type.SetSP(type_sp);
   }
   if (log) {