Use MakeUnique. (#1837)

This CL replaces instances of reset(new ..) with MakeUnique.
diff --git a/source/comp/bit_stream.h b/source/comp/bit_stream.h
index 69c9e8b..5f82344 100644
--- a/source/comp/bit_stream.h
+++ b/source/comp/bit_stream.h
@@ -21,6 +21,7 @@
 #include <bitset>
 #include <cassert>
 #include <cstdint>
+#include <cstring>
 #include <functional>
 #include <sstream>
 #include <string>
diff --git a/source/comp/markv_codec.cpp b/source/comp/markv_codec.cpp
index bdf7ee1..ae3ce79 100644
--- a/source/comp/markv_codec.cpp
+++ b/source/comp/markv_codec.cpp
@@ -22,6 +22,7 @@
 #include "source/latest_version_glsl_std_450_header.h"
 #include "source/latest_version_opencl_std_header.h"
 #include "source/opcode.h"
+#include "source/util/make_unique.h"
 
 namespace spvtools {
 namespace comp {
@@ -47,7 +48,7 @@
 
   std::unique_ptr<HuffmanCodec<uint32_t>> codec;
 
-  codec.reset(new HuffmanCodec<uint32_t>(std::map<uint32_t, uint32_t>({
+  codec = MakeUnique<HuffmanCodec<uint32_t>>(std::map<uint32_t, uint32_t>({
       {0, 5},
       {1, 40},
       {2, 10},
@@ -59,10 +60,10 @@
       {8, 3},
       {9, 3},
       {MarkvCodec::kMtfRankEncodedByValueSignal, 10},
-  })));
+  }));
   codecs.emplace(kMtfAll, std::move(codec));
 
-  codec.reset(new HuffmanCodec<uint32_t>(std::map<uint32_t, uint32_t>({
+  codec = MakeUnique<HuffmanCodec<uint32_t>>(std::map<uint32_t, uint32_t>({
       {1, 50},
       {2, 20},
       {3, 5},
@@ -73,7 +74,7 @@
       {8, 1},
       {9, 1},
       {MarkvCodec::kMtfRankEncodedByValueSignal, 10},
-  })));
+  }));
   codecs.emplace(kMtfGenericNonZeroRank, std::move(codec));
 
   return codecs;
diff --git a/source/comp/markv_decoder.h b/source/comp/markv_decoder.h
index cb1c725..4d8402b 100644
--- a/source/comp/markv_decoder.h
+++ b/source/comp/markv_decoder.h
@@ -16,6 +16,7 @@
 #include "source/comp/markv.h"
 #include "source/comp/markv_codec.h"
 #include "source/comp/markv_logger.h"
+#include "source/util/make_unique.h"
 
 #ifndef SOURCE_COMP_MARKV_DECODER_H_
 #define SOURCE_COMP_MARKV_DECODER_H_
@@ -44,7 +45,7 @@
   // Creates an internal logger which writes comments on the decoding process.
   void CreateLogger(MarkvLogConsumer log_consumer,
                     MarkvDebugConsumer debug_consumer) {
-    logger_.reset(new MarkvLogger(log_consumer, debug_consumer));
+    logger_ = MakeUnique<MarkvLogger>(log_consumer, debug_consumer);
   }
 
   // Decodes SPIR-V from MARK-V and stores the words in |spirv_binary|.
diff --git a/source/comp/markv_encoder.h b/source/comp/markv_encoder.h
index 830c14d..2184312 100644
--- a/source/comp/markv_encoder.h
+++ b/source/comp/markv_encoder.h
@@ -16,6 +16,7 @@
 #include "source/comp/markv.h"
 #include "source/comp/markv_codec.h"
 #include "source/comp/markv_logger.h"
+#include "source/util/make_unique.h"
 
 #ifndef SOURCE_COMP_MARKV_ENCODER_H_
 #define SOURCE_COMP_MARKV_ENCODER_H_
@@ -30,6 +31,7 @@
 // Encoded binary is written to an internally maintained bitstream.
 // After the last instruction is encoded, the resulting MARK-V binary can be
 // acquired by calling GetMarkvBinary().
+//
 // The encoder uses SPIR-V validator to keep internal state, therefore
 // SPIR-V binary needs to be able to pass validator checks.
 // CreateCommentsLogger() can be used to enable the encoder to write comments
@@ -57,7 +59,7 @@
   // Creates an internal logger which writes comments on the encoding process.
   void CreateLogger(MarkvLogConsumer log_consumer,
                     MarkvDebugConsumer debug_consumer) {
-    logger_.reset(new MarkvLogger(log_consumer, debug_consumer));
+    logger_ = MakeUnique<MarkvLogger>(log_consumer, debug_consumer);
     writer_.SetCallback(
         [this](const std::string& str) { logger_->AppendBitSequence(str); });
   }
@@ -91,7 +93,7 @@
   // Disassembly should contain all instructions in the module separated by
   // \n, and no header.
   void SetDisassembly(std::string&& disassembly) {
-    disassembly_.reset(new std::stringstream(std::move(disassembly)));
+    disassembly_ = MakeUnique<std::stringstream>(std::move(disassembly));
   }
 
   // Extracts the next instruction line from the disassembly and logs it.
diff --git a/source/disassemble.cpp b/source/disassemble.cpp
index 11842cf..c116f50 100644
--- a/source/disassemble.cpp
+++ b/source/disassemble.cpp
@@ -35,6 +35,7 @@
 #include "source/spirv_constant.h"
 #include "source/spirv_endian.h"
 #include "source/util/hex_float.h"
+#include "source/util/make_unique.h"
 #include "spirv-tools/libspirv.h"
 
 namespace {
@@ -419,8 +420,8 @@
   std::unique_ptr<spvtools::FriendlyNameMapper> friendly_mapper;
   spvtools::NameMapper name_mapper = spvtools::GetTrivialNameMapper();
   if (options & SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES) {
-    friendly_mapper.reset(
-        new spvtools::FriendlyNameMapper(&hijack_context, code, wordCount));
+    friendly_mapper = spvtools::MakeUnique<spvtools::FriendlyNameMapper>(
+        &hijack_context, code, wordCount);
     name_mapper = friendly_mapper->GetNameMapper();
   }
 
@@ -452,8 +453,8 @@
   std::unique_ptr<spvtools::FriendlyNameMapper> friendly_mapper;
   spvtools::NameMapper name_mapper = spvtools::GetTrivialNameMapper();
   if (options & SPV_BINARY_TO_TEXT_OPTION_FRIENDLY_NAMES) {
-    friendly_mapper.reset(
-        new spvtools::FriendlyNameMapper(context, code, wordCount));
+    friendly_mapper = spvtools::MakeUnique<spvtools::FriendlyNameMapper>(
+        context, code, wordCount);
     name_mapper = friendly_mapper->GetNameMapper();
   }
 
diff --git a/source/enum_set.h b/source/enum_set.h
index b428eff..e4ef297 100644
--- a/source/enum_set.h
+++ b/source/enum_set.h
@@ -22,6 +22,7 @@
 #include <utility>
 
 #include "source/latest_version_spirv_header.h"
+#include "source/util/make_unique.h"
 
 namespace spvtools {
 
@@ -152,7 +153,7 @@
   // allocated if one doesn't exist yet.  Returns overflow_set_.
   OverflowSetType& Overflow() {
     if (overflow_.get() == nullptr) {
-      overflow_.reset(new OverflowSetType);
+      overflow_ = MakeUnique<OverflowSetType>();
     }
     return *overflow_;
   }
diff --git a/source/opt/inline_pass.cpp b/source/opt/inline_pass.cpp
index 6db027c..5a88ef5 100644
--- a/source/opt/inline_pass.cpp
+++ b/source/opt/inline_pass.cpp
@@ -20,6 +20,7 @@
 #include <utility>
 
 #include "source/cfa.h"
+#include "source/util/make_unique.h"
 
 // Indices of operands in SPIR-V instructions
 
@@ -336,7 +337,7 @@
           firstBlock = true;
         }
         // Create first/next block.
-        new_blk_ptr.reset(new BasicBlock(NewLabel(labelId)));
+        new_blk_ptr = MakeUnique<BasicBlock>(NewLabel(labelId));
         if (firstBlock) {
           // Copy contents of original caller block up to call instruction.
           for (auto cii = call_block_itr->begin(); cii != call_inst_itr;
@@ -362,7 +363,7 @@
             AddBranch(guard_block_id, &new_blk_ptr);
             new_blocks->push_back(std::move(new_blk_ptr));
             // Start the next block.
-            new_blk_ptr.reset(new BasicBlock(NewLabel(guard_block_id)));
+            new_blk_ptr = MakeUnique<BasicBlock>(NewLabel(guard_block_id));
             // Reset the mapping of the callee's entry block to point to
             // the guard block.  Do this so we can fix up phis later on to
             // satisfy dominance.
@@ -383,14 +384,15 @@
             singleTripLoopHeaderId = this->TakeNextId();
             AddBranch(singleTripLoopHeaderId, &new_blk_ptr);
             new_blocks->push_back(std::move(new_blk_ptr));
-            new_blk_ptr.reset(new BasicBlock(NewLabel(singleTripLoopHeaderId)));
+            new_blk_ptr =
+                MakeUnique<BasicBlock>(NewLabel(singleTripLoopHeaderId));
             returnLabelId = this->TakeNextId();
             singleTripLoopContinueId = this->TakeNextId();
             AddLoopMerge(returnLabelId, singleTripLoopContinueId, &new_blk_ptr);
             uint32_t postHeaderId = this->TakeNextId();
             AddBranch(postHeaderId, &new_blk_ptr);
             new_blocks->push_back(std::move(new_blk_ptr));
-            new_blk_ptr.reset(new BasicBlock(NewLabel(postHeaderId)));
+            new_blk_ptr = MakeUnique<BasicBlock>(NewLabel(postHeaderId));
             multiBlocks = true;
             // Reset the mapping of the callee's entry block to point to
             // the post-header block.  Do this so we can fix up phis later
@@ -432,14 +434,14 @@
             // to accommodate multiple returns, insert the continue
             // target block now, with a false branch back to the loop header.
             new_blocks->push_back(std::move(new_blk_ptr));
-            new_blk_ptr.reset(
-                new BasicBlock(NewLabel(singleTripLoopContinueId)));
+            new_blk_ptr =
+                MakeUnique<BasicBlock>(NewLabel(singleTripLoopContinueId));
             AddBranchCond(GetFalseId(), singleTripLoopHeaderId, returnLabelId,
                           &new_blk_ptr);
           }
           // Generate the return block.
           new_blocks->push_back(std::move(new_blk_ptr));
-          new_blk_ptr.reset(new BasicBlock(NewLabel(returnLabelId)));
+          new_blk_ptr = MakeUnique<BasicBlock>(NewLabel(returnLabelId));
           multiBlocks = true;
         }
         // Load return value into result id of call, if it exists.
diff --git a/source/opt/ir_context.h b/source/opt/ir_context.h
index af736bc..a9d892f 100644
--- a/source/opt/ir_context.h
+++ b/source/opt/ir_context.h
@@ -39,6 +39,7 @@
 #include "source/opt/scalar_analysis.h"
 #include "source/opt/type_manager.h"
 #include "source/opt/value_number_table.h"
+#include "source/util/make_unique.h"
 
 namespace spvtools {
 namespace opt {
@@ -274,7 +275,7 @@
   // remains active and it is never re-built.
   analysis::ConstantManager* get_constant_mgr() {
     if (!constant_mgr_)
-      constant_mgr_.reset(new analysis::ConstantManager(this));
+      constant_mgr_ = MakeUnique<analysis::ConstantManager>(this);
     return constant_mgr_.get();
   }
 
@@ -283,7 +284,7 @@
   // is never re-built.
   analysis::TypeManager* get_type_mgr() {
     if (!type_mgr_)
-      type_mgr_.reset(new analysis::TypeManager(consumer(), this));
+      type_mgr_ = MakeUnique<analysis::TypeManager>(consumer(), this);
     return type_mgr_.get();
   }
 
@@ -450,7 +451,7 @@
 
   const InstructionFolder& get_instruction_folder() {
     if (!inst_folder_) {
-      inst_folder_.reset(new InstructionFolder(this));
+      inst_folder_ = MakeUnique<InstructionFolder>(this);
     }
     return *inst_folder_;
   }
@@ -458,7 +459,7 @@
  private:
   // Builds the def-use manager from scratch, even if it was already valid.
   void BuildDefUseManager() {
-    def_use_mgr_.reset(new analysis::DefUseManager(module()));
+    def_use_mgr_ = MakeUnique<analysis::DefUseManager>(module());
     valid_analyses_ = valid_analyses_ | kAnalysisDefUse;
   }
 
@@ -476,30 +477,30 @@
   }
 
   void BuildDecorationManager() {
-    decoration_mgr_.reset(new analysis::DecorationManager(module()));
+    decoration_mgr_ = MakeUnique<analysis::DecorationManager>(module());
     valid_analyses_ = valid_analyses_ | kAnalysisDecorations;
   }
 
   void BuildCFG() {
-    cfg_.reset(new CFG(module()));
+    cfg_ = MakeUnique<CFG>(module());
     valid_analyses_ = valid_analyses_ | kAnalysisCFG;
   }
 
   void BuildScalarEvolutionAnalysis() {
-    scalar_evolution_analysis_.reset(new ScalarEvolutionAnalysis(this));
+    scalar_evolution_analysis_ = MakeUnique<ScalarEvolutionAnalysis>(this);
     valid_analyses_ = valid_analyses_ | kAnalysisScalarEvolution;
   }
 
   // Builds the liveness analysis from scratch, even if it was already valid.
   void BuildRegPressureAnalysis() {
-    reg_pressure_.reset(new LivenessAnalysis(this));
+    reg_pressure_ = MakeUnique<LivenessAnalysis>(this);
     valid_analyses_ = valid_analyses_ | kAnalysisRegisterPressure;
   }
 
   // Builds the value number table analysis from scratch, even if it was already
   // valid.
   void BuildValueNumberTable() {
-    vn_table_.reset(new ValueNumberTable(this));
+    vn_table_ = MakeUnique<ValueNumberTable>(this);
     valid_analyses_ = valid_analyses_ | kAnalysisValueNumberTable;
   }
 
@@ -521,7 +522,7 @@
 
   // Analyzes the features in the owned module. Builds the manager if required.
   void AnalyzeFeatures() {
-    feature_mgr_.reset(new FeatureManager(grammar_));
+    feature_mgr_ = MakeUnique<FeatureManager>(grammar_);
     feature_mgr_->Analyze(module());
   }
 
@@ -832,7 +833,7 @@
 }
 
 void IRContext::BuildIdToNameMap() {
-  id_to_name_.reset(new std::multimap<uint32_t, Instruction*>());
+  id_to_name_ = MakeUnique<std::multimap<uint32_t, Instruction*>>();
   for (Instruction& debug_inst : debugs2()) {
     if (debug_inst.opcode() == SpvOpMemberName ||
         debug_inst.opcode() == SpvOpName) {
diff --git a/source/opt/ir_loader.cpp b/source/opt/ir_loader.cpp
index 3d7412d..46e2bee 100644
--- a/source/opt/ir_loader.cpp
+++ b/source/opt/ir_loader.cpp
@@ -18,6 +18,7 @@
 
 #include "source/opt/log.h"
 #include "source/opt/reflect.h"
+#include "source/util/make_unique.h"
 
 namespace spvtools {
 namespace opt {
@@ -50,7 +51,7 @@
       Error(consumer_, src, loc, "function inside function");
       return false;
     }
-    function_.reset(new Function(std::move(spv_inst)));
+    function_ = MakeUnique<Function>(std::move(spv_inst));
   } else if (opcode == SpvOpFunctionEnd) {
     if (function_ == nullptr) {
       Error(consumer_, src, loc,
@@ -73,7 +74,7 @@
       Error(consumer_, src, loc, "OpLabel inside basic block");
       return false;
     }
-    block_.reset(new BasicBlock(std::move(spv_inst)));
+    block_ = MakeUnique<BasicBlock>(std::move(spv_inst));
   } else if (IsTerminatorInst(opcode)) {
     if (function_ == nullptr) {
       Error(consumer_, src, loc, "terminator instruction outside function");
diff --git a/source/opt/type_manager.cpp b/source/opt/type_manager.cpp
index bb2beb0..bd5221b 100644
--- a/source/opt/type_manager.cpp
+++ b/source/opt/type_manager.cpp
@@ -206,10 +206,10 @@
   id = context()->TakeNextId();
   RegisterType(id, *type);
   switch (type->kind()) {
-#define DefineParameterlessCase(kind)                                  \
-  case Type::k##kind:                                                  \
-    typeInst.reset(new Instruction(context(), SpvOpType##kind, 0, id,  \
-                                   std::initializer_list<Operand>{})); \
+#define DefineParameterlessCase(kind)                                     \
+  case Type::k##kind:                                                     \
+    typeInst = MakeUnique<Instruction>(context(), SpvOpType##kind, 0, id, \
+                                       std::initializer_list<Operand>{}); \
     break;
     DefineParameterlessCase(Void);
     DefineParameterlessCase(Bool);
@@ -222,43 +222,43 @@
     DefineParameterlessCase(NamedBarrier);
 #undef DefineParameterlessCase
     case Type::kInteger:
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeInt, 0, id,
           std::initializer_list<Operand>{
               {SPV_OPERAND_TYPE_LITERAL_INTEGER, {type->AsInteger()->width()}},
               {SPV_OPERAND_TYPE_LITERAL_INTEGER,
-               {(type->AsInteger()->IsSigned() ? 1u : 0u)}}}));
+               {(type->AsInteger()->IsSigned() ? 1u : 0u)}}});
       break;
     case Type::kFloat:
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeFloat, 0, id,
           std::initializer_list<Operand>{
-              {SPV_OPERAND_TYPE_LITERAL_INTEGER, {type->AsFloat()->width()}}}));
+              {SPV_OPERAND_TYPE_LITERAL_INTEGER, {type->AsFloat()->width()}}});
       break;
     case Type::kVector: {
       uint32_t subtype = GetTypeInstruction(type->AsVector()->element_type());
-      typeInst.reset(
-          new Instruction(context(), SpvOpTypeVector, 0, id,
-                          std::initializer_list<Operand>{
-                              {SPV_OPERAND_TYPE_ID, {subtype}},
-                              {SPV_OPERAND_TYPE_LITERAL_INTEGER,
-                               {type->AsVector()->element_count()}}}));
+      typeInst =
+          MakeUnique<Instruction>(context(), SpvOpTypeVector, 0, id,
+                                  std::initializer_list<Operand>{
+                                      {SPV_OPERAND_TYPE_ID, {subtype}},
+                                      {SPV_OPERAND_TYPE_LITERAL_INTEGER,
+                                       {type->AsVector()->element_count()}}});
       break;
     }
     case Type::kMatrix: {
       uint32_t subtype = GetTypeInstruction(type->AsMatrix()->element_type());
-      typeInst.reset(
-          new Instruction(context(), SpvOpTypeMatrix, 0, id,
-                          std::initializer_list<Operand>{
-                              {SPV_OPERAND_TYPE_ID, {subtype}},
-                              {SPV_OPERAND_TYPE_LITERAL_INTEGER,
-                               {type->AsMatrix()->element_count()}}}));
+      typeInst =
+          MakeUnique<Instruction>(context(), SpvOpTypeMatrix, 0, id,
+                                  std::initializer_list<Operand>{
+                                      {SPV_OPERAND_TYPE_ID, {subtype}},
+                                      {SPV_OPERAND_TYPE_LITERAL_INTEGER,
+                                       {type->AsMatrix()->element_count()}}});
       break;
     }
     case Type::kImage: {
       const Image* image = type->AsImage();
       uint32_t subtype = GetTypeInstruction(image->sampled_type());
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeImage, 0, id,
           std::initializer_list<Operand>{
               {SPV_OPERAND_TYPE_ID, {subtype}},
@@ -273,32 +273,32 @@
               {SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT,
                {static_cast<uint32_t>(image->format())}},
               {SPV_OPERAND_TYPE_ACCESS_QUALIFIER,
-               {static_cast<uint32_t>(image->access_qualifier())}}}));
+               {static_cast<uint32_t>(image->access_qualifier())}}});
       break;
     }
     case Type::kSampledImage: {
       uint32_t subtype =
           GetTypeInstruction(type->AsSampledImage()->image_type());
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeSampledImage, 0, id,
-          std::initializer_list<Operand>{{SPV_OPERAND_TYPE_ID, {subtype}}}));
+          std::initializer_list<Operand>{{SPV_OPERAND_TYPE_ID, {subtype}}});
       break;
     }
     case Type::kArray: {
       uint32_t subtype = GetTypeInstruction(type->AsArray()->element_type());
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeArray, 0, id,
           std::initializer_list<Operand>{
               {SPV_OPERAND_TYPE_ID, {subtype}},
-              {SPV_OPERAND_TYPE_ID, {type->AsArray()->LengthId()}}}));
+              {SPV_OPERAND_TYPE_ID, {type->AsArray()->LengthId()}}});
       break;
     }
     case Type::kRuntimeArray: {
       uint32_t subtype =
           GetTypeInstruction(type->AsRuntimeArray()->element_type());
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeRuntimeArray, 0, id,
-          std::initializer_list<Operand>{{SPV_OPERAND_TYPE_ID, {subtype}}}));
+          std::initializer_list<Operand>{{SPV_OPERAND_TYPE_ID, {subtype}}});
       break;
     }
     case Type::kStruct: {
@@ -307,7 +307,8 @@
       for (auto ty : structTy->element_types()) {
         ops.push_back(Operand(SPV_OPERAND_TYPE_ID, {GetTypeInstruction(ty)}));
       }
-      typeInst.reset(new Instruction(context(), SpvOpTypeStruct, 0, id, ops));
+      typeInst =
+          MakeUnique<Instruction>(context(), SpvOpTypeStruct, 0, id, ops);
       break;
     }
     case Type::kOpaque: {
@@ -317,21 +318,21 @@
       std::vector<uint32_t> words(size / 4 + 1, 0);
       char* dst = reinterpret_cast<char*>(words.data());
       strncpy(dst, opaque->name().c_str(), size);
-      typeInst.reset(
-          new Instruction(context(), SpvOpTypeOpaque, 0, id,
-                          std::initializer_list<Operand>{
-                              {SPV_OPERAND_TYPE_LITERAL_STRING, words}}));
+      typeInst = MakeUnique<Instruction>(
+          context(), SpvOpTypeOpaque, 0, id,
+          std::initializer_list<Operand>{
+              {SPV_OPERAND_TYPE_LITERAL_STRING, words}});
       break;
     }
     case Type::kPointer: {
       const Pointer* pointer = type->AsPointer();
       uint32_t subtype = GetTypeInstruction(pointer->pointee_type());
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypePointer, 0, id,
           std::initializer_list<Operand>{
               {SPV_OPERAND_TYPE_STORAGE_CLASS,
                {static_cast<uint32_t>(pointer->storage_class())}},
-              {SPV_OPERAND_TYPE_ID, {subtype}}}));
+              {SPV_OPERAND_TYPE_ID, {subtype}}});
       break;
     }
     case Type::kFunction: {
@@ -342,24 +343,25 @@
       for (auto ty : function->param_types()) {
         ops.push_back(Operand(SPV_OPERAND_TYPE_ID, {GetTypeInstruction(ty)}));
       }
-      typeInst.reset(new Instruction(context(), SpvOpTypeFunction, 0, id, ops));
+      typeInst =
+          MakeUnique<Instruction>(context(), SpvOpTypeFunction, 0, id, ops);
       break;
     }
     case Type::kPipe:
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypePipe, 0, id,
           std::initializer_list<Operand>{
               {SPV_OPERAND_TYPE_ACCESS_QUALIFIER,
-               {static_cast<uint32_t>(type->AsPipe()->access_qualifier())}}}));
+               {static_cast<uint32_t>(type->AsPipe()->access_qualifier())}}});
       break;
     case Type::kForwardPointer:
-      typeInst.reset(new Instruction(
+      typeInst = MakeUnique<Instruction>(
           context(), SpvOpTypeForwardPointer, 0, 0,
           std::initializer_list<Operand>{
               {SPV_OPERAND_TYPE_ID, {type->AsForwardPointer()->target_id()}},
               {SPV_OPERAND_TYPE_STORAGE_CLASS,
                {static_cast<uint32_t>(
-                   type->AsForwardPointer()->storage_class())}}}));
+                   type->AsForwardPointer()->storage_class())}}});
       break;
     default:
       assert(false && "Unexpected type");
@@ -467,45 +469,44 @@
     case Type::kVector: {
       const Vector* vec_ty = type.AsVector();
       const Type* ele_ty = vec_ty->element_type();
-      rebuilt_ty.reset(
-          new Vector(RebuildType(*ele_ty), vec_ty->element_count()));
+      rebuilt_ty =
+          MakeUnique<Vector>(RebuildType(*ele_ty), vec_ty->element_count());
       break;
     }
     case Type::kMatrix: {
       const Matrix* mat_ty = type.AsMatrix();
       const Type* ele_ty = mat_ty->element_type();
-      rebuilt_ty.reset(
-          new Matrix(RebuildType(*ele_ty), mat_ty->element_count()));
+      rebuilt_ty =
+          MakeUnique<Matrix>(RebuildType(*ele_ty), mat_ty->element_count());
       break;
     }
     case Type::kImage: {
       const Image* image_ty = type.AsImage();
       const Type* ele_ty = image_ty->sampled_type();
-      rebuilt_ty.reset(new Image(RebuildType(*ele_ty), image_ty->dim(),
-                                 image_ty->depth(), image_ty->is_arrayed(),
-                                 image_ty->is_multisampled(),
-                                 image_ty->sampled(), image_ty->format(),
-                                 image_ty->access_qualifier()));
+      rebuilt_ty =
+          MakeUnique<Image>(RebuildType(*ele_ty), image_ty->dim(),
+                            image_ty->depth(), image_ty->is_arrayed(),
+                            image_ty->is_multisampled(), image_ty->sampled(),
+                            image_ty->format(), image_ty->access_qualifier());
       break;
     }
     case Type::kSampledImage: {
       const SampledImage* image_ty = type.AsSampledImage();
       const Type* ele_ty = image_ty->image_type();
-      rebuilt_ty.reset(
-
-          new SampledImage(RebuildType(*ele_ty)));
+      rebuilt_ty = MakeUnique<SampledImage>(RebuildType(*ele_ty));
       break;
     }
     case Type::kArray: {
       const Array* array_ty = type.AsArray();
       const Type* ele_ty = array_ty->element_type();
-      rebuilt_ty.reset(new Array(RebuildType(*ele_ty), array_ty->LengthId()));
+      rebuilt_ty =
+          MakeUnique<Array>(RebuildType(*ele_ty), array_ty->LengthId());
       break;
     }
     case Type::kRuntimeArray: {
       const RuntimeArray* array_ty = type.AsRuntimeArray();
       const Type* ele_ty = array_ty->element_type();
-      rebuilt_ty.reset(new RuntimeArray(RebuildType(*ele_ty)));
+      rebuilt_ty = MakeUnique<RuntimeArray>(RebuildType(*ele_ty));
       break;
     }
     case Type::kStruct: {
@@ -515,7 +516,7 @@
       for (const auto* ele_ty : struct_ty->element_types()) {
         subtypes.push_back(RebuildType(*ele_ty));
       }
-      rebuilt_ty.reset(new Struct(subtypes));
+      rebuilt_ty = MakeUnique<Struct>(subtypes);
       Struct* rebuilt_struct = rebuilt_ty->AsStruct();
       for (auto pair : struct_ty->element_decorations()) {
         uint32_t index = pair.first;
@@ -530,8 +531,8 @@
     case Type::kPointer: {
       const Pointer* pointer_ty = type.AsPointer();
       const Type* ele_ty = pointer_ty->pointee_type();
-      rebuilt_ty.reset(
-          new Pointer(RebuildType(*ele_ty), pointer_ty->storage_class()));
+      rebuilt_ty = MakeUnique<Pointer>(RebuildType(*ele_ty),
+                                       pointer_ty->storage_class());
       break;
     }
     case Type::kFunction: {
@@ -542,13 +543,13 @@
       for (const auto* param_ty : function_ty->param_types()) {
         param_types.push_back(RebuildType(*param_ty));
       }
-      rebuilt_ty.reset(new Function(RebuildType(*ret_ty), param_types));
+      rebuilt_ty = MakeUnique<Function>(RebuildType(*ret_ty), param_types);
       break;
     }
     case Type::kForwardPointer: {
       const ForwardPointer* forward_ptr_ty = type.AsForwardPointer();
-      rebuilt_ty.reset(new ForwardPointer(forward_ptr_ty->target_id(),
-                                          forward_ptr_ty->storage_class()));
+      rebuilt_ty = MakeUnique<ForwardPointer>(forward_ptr_ty->target_id(),
+                                              forward_ptr_ty->storage_class());
       const Pointer* target_ptr = forward_ptr_ty->target_pointer();
       if (target_ptr) {
         rebuilt_ty->AsForwardPointer()->SetTargetPointer(
diff --git a/source/opt/types.cpp b/source/opt/types.cpp
index 6045ff2..15cff54 100644
--- a/source/opt/types.cpp
+++ b/source/opt/types.cpp
@@ -19,6 +19,7 @@
 #include <unordered_set>
 
 #include "source/opt/types.h"
+#include "source/util/make_unique.h"
 
 namespace spvtools {
 namespace opt {
@@ -95,9 +96,9 @@
 std::unique_ptr<Type> Type::Clone() const {
   std::unique_ptr<Type> type;
   switch (kind_) {
-#define DeclareKindCase(kind)                \
-  case k##kind:                              \
-    type.reset(new kind(*this->As##kind())); \
+#define DeclareKindCase(kind)                   \
+  case k##kind:                                 \
+    type = MakeUnique<kind>(*this->As##kind()); \
     break;
     DeclareKindCase(Void);
     DeclareKindCase(Bool);
diff --git a/source/util/make_unique.h b/source/util/make_unique.h
index 4f8f6ec..ad7976c 100644
--- a/source/util/make_unique.h
+++ b/source/util/make_unique.h
@@ -12,8 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef SOURCE_OPT_MAKE_UNIQUE_H_
-#define SOURCE_OPT_MAKE_UNIQUE_H_
+#ifndef SOURCE_UTIL_MAKE_UNIQUE_H_
+#define SOURCE_UTIL_MAKE_UNIQUE_H_
 
 #include <memory>
 #include <utility>
@@ -27,4 +27,4 @@
 
 }  // namespace spvtools
 
-#endif  // SOURCE_OPT_MAKE_UNIQUE_H_
+#endif  // SOURCE_UTIL_MAKE_UNIQUE_H_
diff --git a/source/util/parse_number.cpp b/source/util/parse_number.cpp
index d0b13c6..c3351c2 100644
--- a/source/util/parse_number.cpp
+++ b/source/util/parse_number.cpp
@@ -22,6 +22,7 @@
 #include <tuple>
 
 #include "source/util/hex_float.h"
+#include "source/util/make_unique.h"
 
 namespace spvtools {
 namespace utils {
@@ -34,7 +35,7 @@
  public:
   explicit ErrorMsgStream(std::string* error_msg_sink)
       : error_msg_sink_(error_msg_sink) {
-    if (error_msg_sink_) stream_.reset(new std::ostringstream());
+    if (error_msg_sink_) stream_ = MakeUnique<std::ostringstream>();
   }
   ~ErrorMsgStream() {
     if (error_msg_sink_ && stream_) *error_msg_sink_ = stream_->str();
diff --git a/source/util/small_vector.h b/source/util/small_vector.h
index 54e0054..f2c1147 100644
--- a/source/util/small_vector.h
+++ b/source/util/small_vector.h
@@ -55,7 +55,7 @@
 
   SmallVector(const std::vector<T>& vec) : SmallVector() {
     if (vec.size() > small_size) {
-      large_data_.reset(new std::vector<T>(vec));
+      large_data_ = MakeUnique<std::vector<T>>(vec);
     } else {
       size_ = vec.size();
       for (uint32_t i = 0; i < size_; i++) {
@@ -66,7 +66,7 @@
 
   SmallVector(std::vector<T>&& vec) : SmallVector() {
     if (vec.size() > small_size) {
-      large_data_.reset(new std::vector<T>(std::move(vec)));
+      large_data_ = MakeUnique<std::vector<T>>(std::move(vec));
     } else {
       size_ = vec.size();
       for (uint32_t i = 0; i < size_; i++) {
@@ -82,7 +82,7 @@
         new (small_data_ + (size_++)) T(std::move(*it));
       }
     } else {
-      large_data_.reset(new std::vector<T>(std::move(init_list)));
+      large_data_ = MakeUnique<std::vector<T>>(std::move(init_list));
     }
   }
 
@@ -100,7 +100,7 @@
       if (large_data_) {
         *large_data_ = *that.large_data_;
       } else {
-        large_data_.reset(new std::vector<T>(*that.large_data_));
+        large_data_ = MakeUnique<std::vector<T>>(*that.large_data_);
       }
     } else {
       large_data_.reset(nullptr);
@@ -426,7 +426,7 @@
   // be access through |large_data|.
   void MoveToLargeData() {
     assert(!large_data_);
-    large_data_.reset(new std::vector<T>());
+    large_data_ = MakeUnique<std::vector<T>>();
     for (size_t i = 0; i < size_; ++i) {
       large_data_->emplace_back(std::move(small_data_[i]));
     }
diff --git a/test/opt/pass_fixture.h b/test/opt/pass_fixture.h
index 0306564..9d9eb36 100644
--- a/test/opt/pass_fixture.h
+++ b/test/opt/pass_fixture.h
@@ -191,7 +191,7 @@
 
   // Renews the pass manager, including clearing all previously added passes.
   void RenewPassManger() {
-    manager_.reset(new PassManager());
+    manager_ = MakeUnique<PassManager>();
     manager_->SetMessageConsumer(consumer_);
   }
 
diff --git a/test/opt/types_test.cpp b/test/opt/types_test.cpp
index 0609b7e..c11187e 100644
--- a/test/opt/types_test.cpp
+++ b/test/opt/types_test.cpp
@@ -29,12 +29,13 @@
 class SameTypeTest : public ::testing::Test {
  protected:
   void SetUp() override {
-    void_t_.reset(new Void());
-    u32_t_.reset(new Integer(32, false));
-    f64_t_.reset(new Float(64));
-    v3u32_t_.reset(new Vector(u32_t_.get(), 3));
-    image_t_.reset(new Image(f64_t_.get(), SpvDim2D, 1, 1, 0, 0,
-                             SpvImageFormatR16, SpvAccessQualifierReadWrite));
+    void_t_ = MakeUnique<Void>();
+    u32_t_ = MakeUnique<Integer>(32, false);
+    f64_t_ = MakeUnique<Float>(64);
+    v3u32_t_ = MakeUnique<Vector>(u32_t_.get(), 3);
+    image_t_ =
+        MakeUnique<Image>(f64_t_.get(), SpvDim2D, 1, 1, 0, 0, SpvImageFormatR16,
+                          SpvAccessQualifierReadWrite);
   }
 
   // Element types to be used for constructing other types for testing.
diff --git a/tools/comp/markv_model_factory.cpp b/tools/comp/markv_model_factory.cpp
index dac9bd5..863fcf5 100644
--- a/tools/comp/markv_model_factory.cpp
+++ b/tools/comp/markv_model_factory.cpp
@@ -14,6 +14,7 @@
 
 #include "tools/comp/markv_model_factory.h"
 
+#include "source/util/make_unique.h"
 #include "tools/comp/markv_model_shader.h"
 
 namespace spvtools {
@@ -23,15 +24,15 @@
   std::unique_ptr<MarkvModel> model;
   switch (type) {
     case kMarkvModelShaderLite: {
-      model.reset(new MarkvModelShaderLite());
+      model = MakeUnique<MarkvModelShaderLite>();
       break;
     }
     case kMarkvModelShaderMid: {
-      model.reset(new MarkvModelShaderMid());
+      model = MakeUnique<MarkvModelShaderMid>();
       break;
     }
     case kMarkvModelShaderMax: {
-      model.reset(new MarkvModelShaderMax());
+      model = MakeUnique<MarkvModelShaderMax>();
       break;
     }
     case kMarkvModelUnknown: {
diff --git a/tools/comp/markv_model_shader.cpp b/tools/comp/markv_model_shader.cpp
index 508bf01..8e296cd 100644
--- a/tools/comp/markv_model_shader.cpp
+++ b/tools/comp/markv_model_shader.cpp
@@ -21,6 +21,8 @@
 #include <unordered_set>
 #include <vector>
 
+#include "source/util/make_unique.h"
+
 namespace spvtools {
 namespace comp {
 namespace {
@@ -42,8 +44,8 @@
   const uint16_t kVersionNumber = 1;
   SetModelVersion(kVersionNumber);
 
-  opcode_and_num_operands_huffman_codec_.reset(
-      new HuffmanCodec<uint64_t>(GetOpcodeAndNumOperandsHist()));
+  opcode_and_num_operands_huffman_codec_ =
+      MakeUnique<HuffmanCodec<uint64_t>>(GetOpcodeAndNumOperandsHist());
 
   id_fallback_strategy_ = IdFallbackStrategy::kShortDescriptor;
 }
@@ -52,8 +54,8 @@
   const uint16_t kVersionNumber = 1;
   SetModelVersion(kVersionNumber);
 
-  opcode_and_num_operands_huffman_codec_.reset(
-      new HuffmanCodec<uint64_t>(GetOpcodeAndNumOperandsHist()));
+  opcode_and_num_operands_huffman_codec_ =
+      MakeUnique<HuffmanCodec<uint64_t>>(GetOpcodeAndNumOperandsHist());
   non_id_word_huffman_codecs_ = GetNonIdWordHuffmanCodecs();
   id_descriptor_huffman_codecs_ = GetIdDescriptorHuffmanCodecs();
   descriptors_with_coding_scheme_ = GetDescriptorsWithCodingScheme();
@@ -66,8 +68,8 @@
   const uint16_t kVersionNumber = 1;
   SetModelVersion(kVersionNumber);
 
-  opcode_and_num_operands_huffman_codec_.reset(
-      new HuffmanCodec<uint64_t>(GetOpcodeAndNumOperandsHist()));
+  opcode_and_num_operands_huffman_codec_ =
+      MakeUnique<HuffmanCodec<uint64_t>>(GetOpcodeAndNumOperandsHist());
   opcode_and_num_operands_markov_huffman_codecs_ =
       GetOpcodeAndNumOperandsMarkovHuffmanCodecs();
   non_id_word_huffman_codecs_ = GetNonIdWordHuffmanCodecs();