[llvm] r216925 - unique_ptrify the result of SpecialCaseList::create

David Blaikie dblaikie at gmail.com
Tue Sep 2 11:13:54 PDT 2014


Author: dblaikie
Date: Tue Sep  2 13:13:54 2014
New Revision: 216925

URL: http://llvm.org/viewvc/llvm-project?rev=216925&view=rev
Log:
unique_ptrify the result of SpecialCaseList::create

Modified:
    llvm/trunk/include/llvm/Support/SpecialCaseList.h
    llvm/trunk/lib/Support/SpecialCaseList.cpp
    llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
    llvm/trunk/unittests/Support/SpecialCaseListTest.cpp

Modified: llvm/trunk/include/llvm/Support/SpecialCaseList.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/SpecialCaseList.h?rev=216925&r1=216924&r2=216925&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/SpecialCaseList.h (original)
+++ llvm/trunk/include/llvm/Support/SpecialCaseList.h Tue Sep  2 13:13:54 2014
@@ -60,13 +60,15 @@ class SpecialCaseList {
   /// Parses the special case list from a file. If Path is empty, returns
   /// an empty special case list. On failure, returns 0 and writes an error
   /// message to string.
-  static SpecialCaseList *create(StringRef Path, std::string &Error);
+   static std::unique_ptr<SpecialCaseList> create(StringRef Path,
+                                                  std::string &Error);
   /// Parses the special case list from a memory buffer. On failure, returns
   /// 0 and writes an error message to string.
-  static SpecialCaseList *create(const MemoryBuffer *MB, std::string &Error);
+   static std::unique_ptr<SpecialCaseList> create(const MemoryBuffer *MB,
+                                                  std::string &Error);
   /// Parses the special case list from a file. On failure, reports a fatal
   /// error.
-  static SpecialCaseList *createOrDie(StringRef Path);
+   static std::unique_ptr<SpecialCaseList> createOrDie(StringRef Path);
 
   ~SpecialCaseList();
 

Modified: llvm/trunk/lib/Support/SpecialCaseList.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SpecialCaseList.cpp?rev=216925&r1=216924&r2=216925&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SpecialCaseList.cpp (original)
+++ llvm/trunk/lib/Support/SpecialCaseList.cpp Tue Sep  2 13:13:54 2014
@@ -48,9 +48,10 @@ struct SpecialCaseList::Entry {
 
 SpecialCaseList::SpecialCaseList() : Entries() {}
 
-SpecialCaseList *SpecialCaseList::create(StringRef Path, std::string &Error) {
+std::unique_ptr<SpecialCaseList> SpecialCaseList::create(StringRef Path,
+                                                         std::string &Error) {
   if (Path.empty())
-    return new SpecialCaseList();
+    return std::unique_ptr<SpecialCaseList>(new SpecialCaseList());
   ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
       MemoryBuffer::getFile(Path);
   if (std::error_code EC = FileOrErr.getError()) {
@@ -60,17 +61,17 @@ SpecialCaseList *SpecialCaseList::create
   return create(FileOrErr.get().get(), Error);
 }
 
-SpecialCaseList *SpecialCaseList::create(
-    const MemoryBuffer *MB, std::string &Error) {
+std::unique_ptr<SpecialCaseList> SpecialCaseList::create(const MemoryBuffer *MB,
+                                                         std::string &Error) {
   std::unique_ptr<SpecialCaseList> SCL(new SpecialCaseList());
   if (!SCL->parse(MB, Error))
     return nullptr;
-  return SCL.release();
+  return SCL;
 }
 
-SpecialCaseList *SpecialCaseList::createOrDie(StringRef Path) {
+std::unique_ptr<SpecialCaseList> SpecialCaseList::createOrDie(StringRef Path) {
   std::string Error;
-  if (SpecialCaseList *SCL = create(Path, Error))
+  if (auto SCL = create(Path, Error))
     return SCL;
   report_fatal_error(Error);
 }

Modified: llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp?rev=216925&r1=216924&r2=216925&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp Tue Sep  2 13:13:54 2014
@@ -139,7 +139,7 @@ class DFSanABIList {
   std::unique_ptr<SpecialCaseList> SCL;
 
  public:
-  DFSanABIList(SpecialCaseList *SCL) : SCL(SCL) {}
+   DFSanABIList(std::unique_ptr<SpecialCaseList> SCL) : SCL(std::move(SCL)) {}
 
   /// Returns whether either this function or its source file are listed in the
   /// given category.

Modified: llvm/trunk/unittests/Support/SpecialCaseListTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/SpecialCaseListTest.cpp?rev=216925&r1=216924&r2=216925&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/SpecialCaseListTest.cpp (original)
+++ llvm/trunk/unittests/Support/SpecialCaseListTest.cpp Tue Sep  2 13:13:54 2014
@@ -17,14 +17,15 @@ namespace {
 
 class SpecialCaseListTest : public ::testing::Test {
 protected:
-  SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) {
+  std::unique_ptr<SpecialCaseList> makeSpecialCaseList(StringRef List,
+                                                       std::string &Error) {
     std::unique_ptr<MemoryBuffer> MB = MemoryBuffer::getMemBuffer(List);
     return SpecialCaseList::create(MB.get(), Error);
   }
 
-  SpecialCaseList *makeSpecialCaseList(StringRef List) {
+  std::unique_ptr<SpecialCaseList> makeSpecialCaseList(StringRef List) {
     std::string Error;
-    SpecialCaseList *SCL = makeSpecialCaseList(List, Error);
+    auto SCL = makeSpecialCaseList(List, Error);
     assert(SCL);
     assert(Error == "");
     return SCL;
@@ -32,13 +33,13 @@ protected:
 };
 
 TEST_F(SpecialCaseListTest, Basic) {
-  std::unique_ptr<SpecialCaseList> SCL(
+  std::unique_ptr<SpecialCaseList> SCL =
       makeSpecialCaseList("# This is a comment.\n"
                           "\n"
                           "src:hello\n"
                           "src:bye\n"
                           "src:hi=category\n"
-                          "src:z*=category\n"));
+                          "src:z*=category\n");
   EXPECT_TRUE(SCL->inSection("src", "hello"));
   EXPECT_TRUE(SCL->inSection("src", "bye"));
   EXPECT_TRUE(SCL->inSection("src", "hi", "category"));
@@ -49,38 +50,38 @@ TEST_F(SpecialCaseListTest, Basic) {
 }
 
 TEST_F(SpecialCaseListTest, GlobalInitCompat) {
-  std::unique_ptr<SpecialCaseList> SCL(
-      makeSpecialCaseList("global:foo=init\n"));
+  std::unique_ptr<SpecialCaseList> SCL =
+      makeSpecialCaseList("global:foo=init\n");
   EXPECT_FALSE(SCL->inSection("global", "foo"));
   EXPECT_FALSE(SCL->inSection("global", "bar"));
   EXPECT_TRUE(SCL->inSection("global", "foo", "init"));
   EXPECT_FALSE(SCL->inSection("global", "bar", "init"));
 
-  SCL.reset(makeSpecialCaseList("global-init:foo\n"));
+  SCL = makeSpecialCaseList("global-init:foo\n");
   EXPECT_FALSE(SCL->inSection("global", "foo"));
   EXPECT_FALSE(SCL->inSection("global", "bar"));
   EXPECT_TRUE(SCL->inSection("global", "foo", "init"));
   EXPECT_FALSE(SCL->inSection("global", "bar", "init"));
 
-  SCL.reset(makeSpecialCaseList("type:t2=init\n"));
+  SCL = makeSpecialCaseList("type:t2=init\n");
   EXPECT_FALSE(SCL->inSection("type", "t1"));
   EXPECT_FALSE(SCL->inSection("type", "t2"));
   EXPECT_FALSE(SCL->inSection("type", "t1", "init"));
   EXPECT_TRUE(SCL->inSection("type", "t2", "init"));
 
-  SCL.reset(makeSpecialCaseList("global-init-type:t2\n"));
+  SCL = makeSpecialCaseList("global-init-type:t2\n");
   EXPECT_FALSE(SCL->inSection("type", "t1"));
   EXPECT_FALSE(SCL->inSection("type", "t2"));
   EXPECT_FALSE(SCL->inSection("type", "t1", "init"));
   EXPECT_TRUE(SCL->inSection("type", "t2", "init"));
 
-  SCL.reset(makeSpecialCaseList("src:hello=init\n"));
+  SCL = makeSpecialCaseList("src:hello=init\n");
   EXPECT_FALSE(SCL->inSection("src", "hello"));
   EXPECT_FALSE(SCL->inSection("src", "bye"));
   EXPECT_TRUE(SCL->inSection("src", "hello", "init"));
   EXPECT_FALSE(SCL->inSection("src", "bye", "init"));
 
-  SCL.reset(makeSpecialCaseList("global-init-src:hello\n"));
+  SCL = makeSpecialCaseList("global-init-src:hello\n");
   EXPECT_FALSE(SCL->inSection("src", "hello"));
   EXPECT_FALSE(SCL->inSection("src", "bye"));
   EXPECT_TRUE(SCL->inSection("src", "hello", "init"));
@@ -88,14 +89,14 @@ TEST_F(SpecialCaseListTest, GlobalInitCo
 }
 
 TEST_F(SpecialCaseListTest, Substring) {
-  std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList("src:hello\n"
-                                                           "fun:foo\n"
-                                                           "global:bar\n"));
+  std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("src:hello\n"
+                                                             "fun:foo\n"
+                                                             "global:bar\n");
   EXPECT_FALSE(SCL->inSection("src", "othello"));
   EXPECT_FALSE(SCL->inSection("fun", "tomfoolery"));
   EXPECT_FALSE(SCL->inSection("global", "bartender"));
 
-  SCL.reset(makeSpecialCaseList("fun:*foo*\n"));
+  SCL = makeSpecialCaseList("fun:*foo*\n");
   EXPECT_TRUE(SCL->inSection("fun", "tomfoolery"));
   EXPECT_TRUE(SCL->inSection("fun", "foobar"));
 }
@@ -117,7 +118,7 @@ TEST_F(SpecialCaseListTest, InvalidSpeci
 }
 
 TEST_F(SpecialCaseListTest, EmptySpecialCaseList) {
-  std::unique_ptr<SpecialCaseList> SCL(makeSpecialCaseList(""));
+  std::unique_ptr<SpecialCaseList> SCL = makeSpecialCaseList("");
   EXPECT_FALSE(SCL->inSection("foo", "bar"));
 }
 





More information about the llvm-commits mailing list