From 7b96c4919a33cd13fad2fd99c85e60cac51838e2 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Tue, 2 Sep 2014 18:13:54 +0000 Subject: [PATCH] unique_ptrify the result of SpecialCaseList::create git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216925 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/SpecialCaseList.h | 8 +++-- lib/Support/SpecialCaseList.cpp | 15 ++++---- .../Instrumentation/DataFlowSanitizer.cpp | 2 +- unittests/Support/SpecialCaseListTest.cpp | 35 ++++++++++--------- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/include/llvm/Support/SpecialCaseList.h b/include/llvm/Support/SpecialCaseList.h index 5fc52e64fdb..c734fc8daa8 100644 --- a/include/llvm/Support/SpecialCaseList.h +++ b/include/llvm/Support/SpecialCaseList.h @@ -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 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 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 createOrDie(StringRef Path); ~SpecialCaseList(); diff --git a/lib/Support/SpecialCaseList.cpp b/lib/Support/SpecialCaseList.cpp index b4eeebdd192..da5cd820def 100644 --- a/lib/Support/SpecialCaseList.cpp +++ b/lib/Support/SpecialCaseList.cpp @@ -48,9 +48,10 @@ struct SpecialCaseList::Entry { SpecialCaseList::SpecialCaseList() : Entries() {} -SpecialCaseList *SpecialCaseList::create(StringRef Path, std::string &Error) { +std::unique_ptr SpecialCaseList::create(StringRef Path, + std::string &Error) { if (Path.empty()) - return new SpecialCaseList(); + return std::unique_ptr(new SpecialCaseList()); ErrorOr> FileOrErr = MemoryBuffer::getFile(Path); if (std::error_code EC = FileOrErr.getError()) { @@ -60,17 +61,17 @@ SpecialCaseList *SpecialCaseList::create(StringRef Path, std::string &Error) { return create(FileOrErr.get().get(), Error); } -SpecialCaseList *SpecialCaseList::create( - const MemoryBuffer *MB, std::string &Error) { +std::unique_ptr SpecialCaseList::create(const MemoryBuffer *MB, + std::string &Error) { std::unique_ptr SCL(new SpecialCaseList()); if (!SCL->parse(MB, Error)) return nullptr; - return SCL.release(); + return SCL; } -SpecialCaseList *SpecialCaseList::createOrDie(StringRef Path) { +std::unique_ptr 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); } diff --git a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp index 6c838d1339e..f79b2039528 100644 --- a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp +++ b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp @@ -139,7 +139,7 @@ class DFSanABIList { std::unique_ptr SCL; public: - DFSanABIList(SpecialCaseList *SCL) : SCL(SCL) {} + DFSanABIList(std::unique_ptr SCL) : SCL(std::move(SCL)) {} /// Returns whether either this function or its source file are listed in the /// given category. diff --git a/unittests/Support/SpecialCaseListTest.cpp b/unittests/Support/SpecialCaseListTest.cpp index 1e13dba7753..11fbca04c89 100644 --- a/unittests/Support/SpecialCaseListTest.cpp +++ b/unittests/Support/SpecialCaseListTest.cpp @@ -17,14 +17,15 @@ namespace { class SpecialCaseListTest : public ::testing::Test { protected: - SpecialCaseList *makeSpecialCaseList(StringRef List, std::string &Error) { + std::unique_ptr makeSpecialCaseList(StringRef List, + std::string &Error) { std::unique_ptr MB = MemoryBuffer::getMemBuffer(List); return SpecialCaseList::create(MB.get(), Error); } - SpecialCaseList *makeSpecialCaseList(StringRef List) { + std::unique_ptr 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 SCL( + std::unique_ptr 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 SCL( - makeSpecialCaseList("global:foo=init\n")); + std::unique_ptr 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, GlobalInitCompat) { } TEST_F(SpecialCaseListTest, Substring) { - std::unique_ptr SCL(makeSpecialCaseList("src:hello\n" - "fun:foo\n" - "global:bar\n")); + std::unique_ptr 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, InvalidSpecialCaseList) { } TEST_F(SpecialCaseListTest, EmptySpecialCaseList) { - std::unique_ptr SCL(makeSpecialCaseList("")); + std::unique_ptr SCL = makeSpecialCaseList(""); EXPECT_FALSE(SCL->inSection("foo", "bar")); }