]> granicus.if.org Git - clang/commitdiff
[Tooling] [0/1] Refactor FrontendActionFactory::create() to return std::unique_ptr<>
authorRoman Lebedev <lebedev.ri@gmail.com>
Tue, 27 Feb 2018 15:19:20 +0000 (15:19 +0000)
committerRoman Lebedev <lebedev.ri@gmail.com>
Tue, 27 Feb 2018 15:19:20 +0000 (15:19 +0000)
Summary:
Noticed during review of D41102.

I'm not sure whether there are any principal reasons why it returns raw owning pointer,
or it is just a old code that was not updated post-C++11.

I'm not too sure what testing i should do, because `check-all` is not error clean here for some reason,
but it does not //appear// asif those failures are related to these changes.

This is clang part.
Clang-tools-extra part is D43780.

Reviewers: klimek, bkramer, alexfh, pcc

Reviewed By: alexfh

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D43779

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326201 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
docs/LibTooling.rst
docs/RAVFrontendAction.rst
include/clang/Tooling/Tooling.h
lib/Tooling/Tooling.cpp
tools/clang-refactor/ClangRefactor.cpp
unittests/AST/EvaluateAsRValueTest.cpp
unittests/CrossTU/CrossTranslationUnitTest.cpp
unittests/Sema/CodeCompleteTest.cpp
unittests/Sema/ExternalSemaSourceTest.cpp
unittests/Tooling/CommentHandlerTest.cpp
unittests/Tooling/ExecutionTest.cpp
unittests/Tooling/RefactoringTest.cpp
unittests/Tooling/TestVisitor.h
unittests/Tooling/ToolingTest.cpp

index 75ef6a0fe7ea69d319eeec949e570ef1d9f672f6..848fa79bb60fff6aaaa110012bc89ce0bdad89d0 100644 (file)
@@ -34,7 +34,7 @@ looked for.  Let me give you an example:
   TEST(runToolOnCode, CanSyntaxCheckCode) {
     // runToolOnCode returns whether the action was correctly run over the
     // given code.
-    EXPECT_TRUE(runToolOnCode(new clang::SyntaxOnlyAction, "class X {};"));
+    EXPECT_TRUE(runToolOnCode(llvm::make_unique<clang::SyntaxOnlyAction>(), "class X {};"));
   }
 
 Writing a standalone tool
index c37d3c0e812ec26b9d2a8748ed41d7e87c9a3933..d62879ffd0618f7ec8137e00e32745d47a5703ad 100644 (file)
@@ -196,7 +196,7 @@ Now we can combine all of the above into a small example program:
 
       int main(int argc, char **argv) {
         if (argc > 1) {
-          clang::tooling::runToolOnCode(new FindNamedClassAction, argv[1]);
+          clang::tooling::runToolOnCode(llvm::make_unique<FindNamedClassAction>(), argv[1]);
         }
       }
 
index 8ddfef37074bcbcd3e525f9c53aaa7cc3169b410..14cbf015b0170680cdd49865c902bc9bfe7dd407 100644 (file)
@@ -94,7 +94,7 @@ public:
   /// \brief Returns a new clang::FrontendAction.
   ///
   /// The caller takes ownership of the returned action.
-  virtual clang::FrontendAction *create() = 0;
+  virtual std::unique_ptr<clang::FrontendAction> create() = 0;
 };
 
 /// \brief Returns a new FrontendActionFactory for a given type.
@@ -149,8 +149,8 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
 ///                         clang modules.
 ///
 /// \return - True if 'ToolAction' was successfully executed.
-bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code,
-                   const Twine &FileName = "input.cc",
+bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
+                   const Twine &Code, const Twine &FileName = "input.cc",
                    std::shared_ptr<PCHContainerOperations> PCHContainerOps =
                        std::make_shared<PCHContainerOperations>());
 
@@ -172,7 +172,7 @@ typedef std::vector<std::pair<std::string, std::string>> FileContentMappings;
 ///
 /// \return - True if 'ToolAction' was successfully executed.
 bool runToolOnCodeWithArgs(
-    clang::FrontendAction *ToolAction, const Twine &Code,
+    std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
     const std::vector<std::string> &Args, const Twine &FileName = "input.cc",
     const Twine &ToolName = "clang-tool",
     std::shared_ptr<PCHContainerOperations> PCHContainerOps =
@@ -226,8 +226,8 @@ public:
   /// ownership.
   /// \param PCHContainerOps The PCHContainerOperations for loading and creating
   /// clang modules.
-  ToolInvocation(std::vector<std::string> CommandLine, FrontendAction *FAction,
-                 FileManager *Files,
+  ToolInvocation(std::vector<std::string> CommandLine,
+                 std::unique_ptr<FrontendAction> FAction, FileManager *Files,
                  std::shared_ptr<PCHContainerOperations> PCHContainerOps =
                      std::make_shared<PCHContainerOperations>());
 
@@ -367,7 +367,9 @@ template <typename T>
 std::unique_ptr<FrontendActionFactory> newFrontendActionFactory() {
   class SimpleFrontendActionFactory : public FrontendActionFactory {
   public:
-    clang::FrontendAction *create() override { return new T; }
+    std::unique_ptr<clang::FrontendAction> create() override {
+      return llvm::make_unique<T>();
+    }
   };
 
   return std::unique_ptr<FrontendActionFactory>(
@@ -383,8 +385,9 @@ inline std::unique_ptr<FrontendActionFactory> newFrontendActionFactory(
                                           SourceFileCallbacks *Callbacks)
       : ConsumerFactory(ConsumerFactory), Callbacks(Callbacks) {}
 
-    clang::FrontendAction *create() override {
-      return new ConsumerFactoryAdaptor(ConsumerFactory, Callbacks);
+    std::unique_ptr<clang::FrontendAction> create() override {
+      return llvm::make_unique<ConsumerFactoryAdaptor>(ConsumerFactory,
+                                                       Callbacks);
     }
 
   private:
index 7ae2950037ba54bf4f15938c731b26fc1a576d3f..82abede8031d8827a4e327192391140d85564a3e 100644 (file)
@@ -104,12 +104,12 @@ clang::CompilerInvocation *newInvocation(
   return Invocation;
 }
 
-bool runToolOnCode(clang::FrontendAction *ToolAction, const Twine &Code,
-                   const Twine &FileName,
+bool runToolOnCode(std::unique_ptr<FrontendAction> ToolAction,
+                   const Twine &Code, const Twine &FileName,
                    std::shared_ptr<PCHContainerOperations> PCHContainerOps) {
-  return runToolOnCodeWithArgs(ToolAction, Code, std::vector<std::string>(),
-                               FileName, "clang-tool",
-                               std::move(PCHContainerOps));
+  return runToolOnCodeWithArgs(std::move(ToolAction), Code,
+                               std::vector<std::string>(), FileName,
+                               "clang-tool", std::move(PCHContainerOps));
 }
 
 static std::vector<std::string>
@@ -125,7 +125,7 @@ getSyntaxOnlyToolArgs(const Twine &ToolName,
 }
 
 bool runToolOnCodeWithArgs(
-    clang::FrontendAction *ToolAction, const Twine &Code,
+    std::unique_ptr<FrontendAction> ToolAction, const Twine &Code,
     const std::vector<std::string> &Args, const Twine &FileName,
     const Twine &ToolName,
     std::shared_ptr<PCHContainerOperations> PCHContainerOps,
@@ -143,8 +143,7 @@ bool runToolOnCodeWithArgs(
   ArgumentsAdjuster Adjuster = getClangStripDependencyFileAdjuster();
   ToolInvocation Invocation(
       getSyntaxOnlyToolArgs(ToolName, Adjuster(Args, FileNameRef), FileNameRef),
-      ToolAction, Files.get(),
-      std::move(PCHContainerOps));
+      std::move(ToolAction), Files.get(), std::move(PCHContainerOps));
 
   SmallString<1024> CodeStorage;
   InMemoryFileSystem->addFile(FileNameRef, 0,
@@ -204,15 +203,18 @@ void addTargetAndModeForProgramName(std::vector<std::string> &CommandLine,
 namespace {
 
 class SingleFrontendActionFactory : public FrontendActionFactory {
-  FrontendAction *Action;
+  std::unique_ptr<clang::FrontendAction> Action;
 
 public:
-  SingleFrontendActionFactory(FrontendAction *Action) : Action(Action) {}
+  SingleFrontendActionFactory(std::unique_ptr<clang::FrontendAction> Action)
+      : Action(std::move(Action)) {}
 
-  FrontendAction *create() override { return Action; }
+  std::unique_ptr<clang::FrontendAction> create() override {
+    return std::move(Action);
+  }
 };
 
-}
+} // namespace
 
 ToolInvocation::ToolInvocation(
     std::vector<std::string> CommandLine, ToolAction *Action,
@@ -222,12 +224,13 @@ ToolInvocation::ToolInvocation(
       DiagConsumer(nullptr) {}
 
 ToolInvocation::ToolInvocation(
-    std::vector<std::string> CommandLine, FrontendAction *FAction,
-    FileManager *Files, std::shared_ptr<PCHContainerOperations> PCHContainerOps)
+    std::vector<std::string> CommandLine,
+    std::unique_ptr<FrontendAction> FAction, FileManager *Files,
+    std::shared_ptr<PCHContainerOperations> PCHContainerOps)
     : CommandLine(std::move(CommandLine)),
-      Action(new SingleFrontendActionFactory(FAction)), OwnsAction(true),
-      Files(Files), PCHContainerOps(std::move(PCHContainerOps)),
-      DiagConsumer(nullptr) {}
+      Action(new SingleFrontendActionFactory(std::move(FAction))),
+      OwnsAction(true), Files(Files),
+      PCHContainerOps(std::move(PCHContainerOps)), DiagConsumer(nullptr) {}
 
 ToolInvocation::~ToolInvocation() {
   if (OwnsAction)
index 950b80062cd953a4675e73b86020ea73d2af5ff6..925bc908a42681709105eb5ca37272ded63af326 100644 (file)
@@ -462,7 +462,9 @@ public:
       ToolActionFactory(TUCallbackType Callback)
           : Callback(std::move(Callback)) {}
 
-      FrontendAction *create() override { return new ToolASTAction(Callback); }
+      std::unique_ptr<FrontendAction> create() override {
+        return llvm::make_unique<ToolASTAction>(Callback);
+      }
 
     private:
       TUCallbackType Callback;
index 820edbc7c3e888cda869780ea127ea3aca733920..27371cc72b262e74707e537c76301c85660acfdb 100644 (file)
@@ -90,7 +90,7 @@ TEST(EvaluateAsRValue, FailsGracefullyForUnknownTypes) {
     std::vector<std::string> Args(1, Mode);
     Args.push_back("-fno-delayed-template-parsing");
     ASSERT_TRUE(runToolOnCodeWithArgs(
-      new EvaluateConstantInitializersAction(),
+      llvm::make_unique<EvaluateConstantInitializersAction>(),
       "template <typename T>"
       "struct vector {"
       "  explicit vector(int size);"
index 5fbf56ed43b8d073a4f33f233bb7ccc50f5d4cd4..886e7fb2e61e87a7be1e42bebd9ab7d3453da16c 100644 (file)
@@ -103,7 +103,8 @@ private:
 
 TEST(CrossTranslationUnit, CanLoadFunctionDefinition) {
   bool Success = false;
-  EXPECT_TRUE(tooling::runToolOnCode(new CTUAction(&Success), "int f(int);"));
+  EXPECT_TRUE(tooling::runToolOnCode(llvm::make_unique<CTUAction>(&Success),
+                                     "int f(int);"));
   EXPECT_TRUE(Success);
 }
 
index 8e888cbe528a1c43f0a88a3fd38d05e26423c86e..7eb776e8eb975d1cc8a3a0bd690928233f403bcb 100644 (file)
@@ -100,7 +100,7 @@ VisitedContextResults runCodeCompleteOnCode(StringRef Code) {
 
   auto Action = llvm::make_unique<CodeCompleteAction>(
       offsetToPosition(WithoutToken, TokenOffset), Results);
-  clang::tooling::runToolOnCodeWithArgs(Action.release(), Code, {"-std=c++11"},
+  clang::tooling::runToolOnCodeWithArgs(std::move(Action), Code, {"-std=c++11"},
                                         TestCCName);
   return Results;
 }
index d2cdd633fa148e2ca5908701c686a811f3561290..840861fb85dcc23df3daa08f266eed2fed5d488e 100644 (file)
@@ -221,28 +221,26 @@ public:
 
 // Make sure that the DiagnosticWatcher is not miscounting.
 TEST(ExternalSemaSource, SanityCheck) {
-  std::unique_ptr<ExternalSemaSourceInstaller> Installer(
-      new ExternalSemaSourceInstaller);
+  auto Installer = llvm::make_unique<ExternalSemaSourceInstaller>();
   DiagnosticWatcher Watcher("AAB", "BBB");
   Installer->PushWatcher(&Watcher);
   std::vector<std::string> Args(1, "-std=c++11");
   ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
-      Installer.release(), "namespace AAA { } using namespace AAB;", Args));
+      std::move(Installer), "namespace AAA { } using namespace AAB;", Args));
   ASSERT_EQ(0, Watcher.SeenCount);
 }
 
 // Check that when we add a NamespaceTypeProvider, we use that suggestion
 // instead of the usual suggestion we would use above.
 TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) {
-  std::unique_ptr<ExternalSemaSourceInstaller> Installer(
-      new ExternalSemaSourceInstaller);
+  auto Installer = llvm::make_unique<ExternalSemaSourceInstaller>();
   NamespaceTypoProvider Provider("AAB", "BBB");
   DiagnosticWatcher Watcher("AAB", "BBB");
   Installer->PushSource(&Provider);
   Installer->PushWatcher(&Watcher);
   std::vector<std::string> Args(1, "-std=c++11");
   ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
-      Installer.release(), "namespace AAA { } using namespace AAB;", Args));
+      std::move(Installer), "namespace AAA { } using namespace AAB;", Args));
   ASSERT_LE(0, Provider.CallCount);
   ASSERT_EQ(1, Watcher.SeenCount);
 }
@@ -250,8 +248,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionPrioritized) {
 // Check that we use the first successful TypoCorrection returned from an
 // ExternalSemaSource.
 TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
-  std::unique_ptr<ExternalSemaSourceInstaller> Installer(
-      new ExternalSemaSourceInstaller);
+  auto Installer = llvm::make_unique<ExternalSemaSourceInstaller>();
   NamespaceTypoProvider First("XXX", "BBB");
   NamespaceTypoProvider Second("AAB", "CCC");
   NamespaceTypoProvider Third("AAB", "DDD");
@@ -262,7 +259,7 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
   Installer->PushWatcher(&Watcher);
   std::vector<std::string> Args(1, "-std=c++11");
   ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
-      Installer.release(), "namespace AAA { } using namespace AAB;", Args));
+      std::move(Installer), "namespace AAA { } using namespace AAB;", Args));
   ASSERT_LE(1, First.CallCount);
   ASSERT_LE(1, Second.CallCount);
   ASSERT_EQ(0, Third.CallCount);
@@ -270,15 +267,14 @@ TEST(ExternalSemaSource, ExternalTypoCorrectionOrdering) {
 }
 
 TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) {
-  std::unique_ptr<ExternalSemaSourceInstaller> Installer(
-      new ExternalSemaSourceInstaller);
+  auto Installer = llvm::make_unique<ExternalSemaSourceInstaller>();
   FunctionTypoProvider Provider("aaa", "bbb");
   DiagnosticWatcher Watcher("aaa", "bbb");
   Installer->PushSource(&Provider);
   Installer->PushWatcher(&Watcher);
   std::vector<std::string> Args(1, "-std=c++11");
   ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
-      Installer.release(), "namespace AAA { } void foo() { AAA::aaa(); }",
+      std::move(Installer), "namespace AAA { } void foo() { AAA::aaa(); }",
       Args));
   ASSERT_LE(0, Provider.CallCount);
   ASSERT_EQ(1, Watcher.SeenCount);
@@ -287,15 +283,14 @@ TEST(ExternalSemaSource, ExternalDelayedTypoCorrection) {
 // We should only try MaybeDiagnoseMissingCompleteType if we can't otherwise
 // solve the problem.
 TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) {
-  std::unique_ptr<ExternalSemaSourceInstaller> Installer(
-      new ExternalSemaSourceInstaller);
+  auto Installer = llvm::make_unique<ExternalSemaSourceInstaller>();
   CompleteTypeDiagnoser Diagnoser(false);
   Installer->PushSource(&Diagnoser);
   std::vector<std::string> Args(1, "-std=c++11");
   // This code hits the class template specialization/class member of a class
   // template specialization checks in Sema::RequireCompleteTypeImpl.
   ASSERT_TRUE(clang::tooling::runToolOnCodeWithArgs(
-      Installer.release(),
+      std::move(Installer),
       "template <typename T> struct S { class C { }; }; S<char>::C SCInst;",
       Args));
   ASSERT_EQ(0, Diagnoser.CallCount);
@@ -304,8 +299,7 @@ TEST(ExternalSemaSource, TryOtherTacticsBeforeDiagnosing) {
 // The first ExternalSemaSource where MaybeDiagnoseMissingCompleteType returns
 // true should be the last one called.
 TEST(ExternalSemaSource, FirstDiagnoserTaken) {
-  std::unique_ptr<ExternalSemaSourceInstaller> Installer(
-      new ExternalSemaSourceInstaller);
+  auto Installer = llvm::make_unique<ExternalSemaSourceInstaller>();
   CompleteTypeDiagnoser First(false);
   CompleteTypeDiagnoser Second(true);
   CompleteTypeDiagnoser Third(true);
@@ -314,7 +308,7 @@ TEST(ExternalSemaSource, FirstDiagnoserTaken) {
   Installer->PushSource(&Third);
   std::vector<std::string> Args(1, "-std=c++11");
   ASSERT_FALSE(clang::tooling::runToolOnCodeWithArgs(
-      Installer.release(), "class Incomplete; Incomplete IncompleteInstance;",
+      std::move(Installer), "class Incomplete; Incomplete IncompleteInstance;",
       Args));
   ASSERT_EQ(1, First.CallCount);
   ASSERT_EQ(1, Second.CallCount);
index 9c3abdc4b15e67d95311829a2467c32e5f130609..682f19e9b134d8211e1ce819f6e1449cd8210ee7 100644 (file)
@@ -56,8 +56,8 @@ public:
   CommentVerifier GetVerifier();
 
 protected:
-  ASTFrontendAction *CreateTestAction() override {
-    return new CommentHandlerAction(this);
+  std::unique_ptr<FrontendAction> CreateTestAction() override {
+    return llvm::make_unique<CommentHandlerAction>(this);
   }
 
 private:
index 26db8c6d0ea85da8e8b9c96e0d37e6ae023d61fc..19e5de7823c260cf7b9eea91f151b093add44fc0 100644 (file)
@@ -79,7 +79,9 @@ private:
 class ReportResultActionFactory : public FrontendActionFactory {
 public:
   ReportResultActionFactory(ExecutionContext *Context) : Context(Context) {}
-  FrontendAction *create() override { return new ReportResultAction(Context); }
+  std::unique_ptr<FrontendAction> create() override {
+    return llvm::make_unique<ReportResultAction>(Context);
+  }
 
 private:
   ExecutionContext *const Context;
index 41836f11ee29d6b25109f653c56eef90c90ed06d..d9d82eb43fa939d1b0ad60e49a2f8feff7580bb5 100644 (file)
@@ -650,7 +650,7 @@ template <typename T>
 class TestVisitor : public clang::RecursiveASTVisitor<T> {
 public:
   bool runOver(StringRef Code) {
-    return runToolOnCode(new TestAction(this), Code);
+    return runToolOnCode(llvm::make_unique<TestAction>(this), Code);
   }
 
 protected:
index fb6a76ccadd014f644eb1ca0e9919968db4d3497..acaaabfac71221b6e434e7a897fb79a60365c27d 100644 (file)
@@ -82,8 +82,8 @@ public:
   }
 
 protected:
-  virtual ASTFrontendAction* CreateTestAction() {
-    return new TestAction(this);
+  virtual std::unique_ptr<FrontendAction> CreateTestAction() {
+    return llvm::make_unique<TestAction>(this);
   }
 
   class FindConsumer : public ASTConsumer {
index 6dd0e53c4ddc12bc1b24accd068eb6441a99d9f0..a4fb579038b86a32ddb968e06660baf2aff42c2b 100644 (file)
@@ -64,10 +64,10 @@ class FindTopLevelDeclConsumer : public clang::ASTConsumer {
 
 TEST(runToolOnCode, FindsNoTopLevelDeclOnEmptyCode) {
   bool FoundTopLevelDecl = false;
-  EXPECT_TRUE(
-      runToolOnCode(new TestAction(llvm::make_unique<FindTopLevelDeclConsumer>(
-                        &FoundTopLevelDecl)),
-                    ""));
+  EXPECT_TRUE(runToolOnCode(
+      llvm::make_unique<TestAction>(
+          llvm::make_unique<FindTopLevelDeclConsumer>(&FoundTopLevelDecl)),
+      ""));
   EXPECT_FALSE(FoundTopLevelDecl);
 }
 
@@ -104,17 +104,17 @@ bool FindClassDeclX(ASTUnit *AST) {
 
 TEST(runToolOnCode, FindsClassDecl) {
   bool FoundClassDeclX = false;
-  EXPECT_TRUE(
-      runToolOnCode(new TestAction(llvm::make_unique<FindClassDeclXConsumer>(
-                        &FoundClassDeclX)),
-                    "class X;"));
+  EXPECT_TRUE(runToolOnCode(
+      llvm::make_unique<TestAction>(
+          llvm::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)),
+      "class X;"));
   EXPECT_TRUE(FoundClassDeclX);
 
   FoundClassDeclX = false;
-  EXPECT_TRUE(
-      runToolOnCode(new TestAction(llvm::make_unique<FindClassDeclXConsumer>(
-                        &FoundClassDeclX)),
-                    "class Y;"));
+  EXPECT_TRUE(runToolOnCode(
+      llvm::make_unique<TestAction>(
+          llvm::make_unique<FindClassDeclXConsumer>(&FoundClassDeclX)),
+      "class Y;"));
   EXPECT_FALSE(FoundClassDeclX);
 }
 
@@ -162,8 +162,8 @@ TEST(ToolInvocation, TestMapVirtualFile) {
   Args.push_back("-Idef");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
-  clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
-                                            Files.get());
+  clang::tooling::ToolInvocation Invocation(
+      Args, llvm::make_unique<SyntaxOnlyAction>(), Files.get());
   InMemoryFileSystem->addFile(
       "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
   InMemoryFileSystem->addFile("def/abc", 0,
@@ -188,8 +188,8 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) {
   Args.push_back("-Idef");
   Args.push_back("-fsyntax-only");
   Args.push_back("test.cpp");
-  clang::tooling::ToolInvocation Invocation(Args, new SyntaxOnlyAction,
-                                            Files.get());
+  clang::tooling::ToolInvocation Invocation(
+      Args, llvm::make_unique<SyntaxOnlyAction>(), Files.get());
   InMemoryFileSystem->addFile(
       "test.cpp", 0, llvm::MemoryBuffer::getMemBuffer("#include <abc>\n"));
   InMemoryFileSystem->addFile("def/abc", 0,
@@ -259,61 +259,64 @@ TEST(runToolOnCode, TestSkipFunctionBody) {
   std::vector<std::string> Args = {"-std=c++11"};
   std::vector<std::string> Args2 = {"-fno-delayed-template-parsing"};
 
-  EXPECT_TRUE(runToolOnCode(new SkipBodyAction,
+  EXPECT_TRUE(runToolOnCode(llvm::make_unique<SkipBodyAction>(),
                             "int skipMe() { an_error_here }"));
-  EXPECT_FALSE(runToolOnCode(new SkipBodyAction,
+  EXPECT_FALSE(runToolOnCode(llvm::make_unique<SkipBodyAction>(),
                              "int skipMeNot() { an_error_here }"));
 
   // Test constructors with initializers
   EXPECT_TRUE(runToolOnCodeWithArgs(
-      new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
       "struct skipMe { skipMe() : an_error() { more error } };", Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-      new SkipBodyAction, "struct skipMe { skipMe(); };"
-                          "skipMe::skipMe() : an_error([](){;}) { more error }",
+      llvm::make_unique<SkipBodyAction>(),
+      "struct skipMe { skipMe(); };"
+      "skipMe::skipMe() : an_error([](){;}) { more error }",
       Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-      new SkipBodyAction, "struct skipMe { skipMe(); };"
-                          "skipMe::skipMe() : an_error{[](){;}} { more error }",
+      llvm::make_unique<SkipBodyAction>(),
+      "struct skipMe { skipMe(); };"
+      "skipMe::skipMe() : an_error{[](){;}} { more error }",
       Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-      new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
       "struct skipMe { skipMe(); };"
       "skipMe::skipMe() : a<b<c>(e)>>(), f{}, g() { error }",
       Args));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-      new SkipBodyAction, "struct skipMe { skipMe() : bases()... { error } };",
-      Args));
+      llvm::make_unique<SkipBodyAction>(),
+      "struct skipMe { skipMe() : bases()... { error } };", Args));
 
   EXPECT_FALSE(runToolOnCodeWithArgs(
-      new SkipBodyAction, "struct skipMeNot { skipMeNot() : an_error() { } };",
-      Args));
-  EXPECT_FALSE(runToolOnCodeWithArgs(new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
+      "struct skipMeNot { skipMeNot() : an_error() { } };", Args));
+  EXPECT_FALSE(runToolOnCodeWithArgs(llvm::make_unique<SkipBodyAction>(),
                                      "struct skipMeNot { skipMeNot(); };"
                                      "skipMeNot::skipMeNot() : an_error() { }",
                                      Args));
 
   // Try/catch
   EXPECT_TRUE(runToolOnCode(
-      new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
       "void skipMe() try { an_error() } catch(error) { error };"));
   EXPECT_TRUE(runToolOnCode(
-      new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
       "struct S { void skipMe() try { an_error() } catch(error) { error } };"));
   EXPECT_TRUE(
-      runToolOnCode(new SkipBodyAction,
+      runToolOnCode(llvm::make_unique<SkipBodyAction>(),
                     "void skipMe() try { an_error() } catch(error) { error; }"
                     "catch(error) { error } catch (error) { }"));
   EXPECT_FALSE(runToolOnCode(
-      new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
       "void skipMe() try something;")); // don't crash while parsing
 
   // Template
-  EXPECT_TRUE(runToolOnCode(
-      new SkipBodyAction, "template<typename T> int skipMe() { an_error_here }"
-                          "int x = skipMe<int>();"));
+  EXPECT_TRUE(
+      runToolOnCode(llvm::make_unique<SkipBodyAction>(),
+                    "template<typename T> int skipMe() { an_error_here }"
+                    "int x = skipMe<int>();"));
   EXPECT_FALSE(runToolOnCodeWithArgs(
-      new SkipBodyAction,
+      llvm::make_unique<SkipBodyAction>(),
       "template<typename T> int skipMeNot() { an_error_here }", Args2));
 }
 
@@ -327,7 +330,8 @@ TEST(runToolOnCodeWithArgs, TestNoDepFile) {
   Args.push_back(DepFilePath.str());
   Args.push_back("-MF");
   Args.push_back(DepFilePath.str());
-  EXPECT_TRUE(runToolOnCodeWithArgs(new SkipBodyAction, "", Args));
+  EXPECT_TRUE(
+      runToolOnCodeWithArgs(llvm::make_unique<SkipBodyAction>(), "", Args));
   EXPECT_FALSE(llvm::sys::fs::exists(DepFilePath.str()));
   EXPECT_FALSE(llvm::sys::fs::remove(DepFilePath.str()));
 }
@@ -351,23 +355,26 @@ private:
 
 TEST(runToolOnCodeWithArgs, DiagnosticsColor) {
 
-  EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "",
-                                    {"-fcolor-diagnostics"}));
-  EXPECT_TRUE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false),
-                                    "", {"-fno-color-diagnostics"}));
-  EXPECT_TRUE(
-      runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(true), "",
-                            {"-fno-color-diagnostics", "-fcolor-diagnostics"}));
-  EXPECT_TRUE(
-      runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false), "",
-                            {"-fcolor-diagnostics", "-fno-color-diagnostics"}));
   EXPECT_TRUE(runToolOnCodeWithArgs(
-      new CheckColoredDiagnosticsAction(true), "",
+      llvm::make_unique<CheckColoredDiagnosticsAction>(true), "",
+      {"-fcolor-diagnostics"}));
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      llvm::make_unique<CheckColoredDiagnosticsAction>(false), "",
+      {"-fno-color-diagnostics"}));
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      llvm::make_unique<CheckColoredDiagnosticsAction>(true), "",
+      {"-fno-color-diagnostics", "-fcolor-diagnostics"}));
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      llvm::make_unique<CheckColoredDiagnosticsAction>(false), "",
+      {"-fcolor-diagnostics", "-fno-color-diagnostics"}));
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      llvm::make_unique<CheckColoredDiagnosticsAction>(true), "",
       {"-fno-color-diagnostics", "-fdiagnostics-color=always"}));
 
   // Check that this test would fail if ShowColors is not what it should.
-  EXPECT_FALSE(runToolOnCodeWithArgs(new CheckColoredDiagnosticsAction(false),
-                                     "", {"-fcolor-diagnostics"}));
+  EXPECT_FALSE(runToolOnCodeWithArgs(
+      llvm::make_unique<CheckColoredDiagnosticsAction>(false), "",
+      {"-fcolor-diagnostics"}));
 }
 
 TEST(ClangToolTest, ArgumentAdjusters) {
@@ -603,7 +610,7 @@ TEST(runToolOnCode, TestResetDiagnostics) {
 
   // Should not crash
   EXPECT_FALSE(
-      runToolOnCode(new ResetDiagnosticAction,
+      runToolOnCode(llvm::make_unique<ResetDiagnosticAction>(),
                     "struct Foo { Foo(int); ~Foo(); struct Fwd _fwd; };"
                     "void func() { long x; Foo f(x); }"));
 }