From c5afb9ed5eb9aeb3eff5158e15844705e8a9ee2d Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 9 Jul 2013 22:03:09 +0000 Subject: [PATCH] Introduce a SpecialCaseList ctor which takes a MemoryBuffer to make it more unit testable, and fix memory leak in the other ctor. Differential Revision: http://llvm-reviews.chandlerc.com/D1090 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185976 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Transforms/Utils/SpecialCaseList.h | 4 ++++ lib/Transforms/Utils/SpecialCaseList.cpp | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/llvm/Transforms/Utils/SpecialCaseList.h b/include/llvm/Transforms/Utils/SpecialCaseList.h index 42d9735c5a7..30e3e46ef5f 100644 --- a/include/llvm/Transforms/Utils/SpecialCaseList.h +++ b/include/llvm/Transforms/Utils/SpecialCaseList.h @@ -35,6 +35,7 @@ namespace llvm { class Function; class GlobalVariable; +class MemoryBuffer; class Module; class Regex; class StringRef; @@ -42,6 +43,8 @@ class StringRef; class SpecialCaseList { public: SpecialCaseList(const StringRef Path); + SpecialCaseList(const MemoryBuffer *MB); + // Returns whether either this function or it's source file are blacklisted. bool isIn(const Function &F) const; // Returns whether either this global or it's source file are blacklisted. @@ -53,6 +56,7 @@ class SpecialCaseList { private: StringMap Entries; + void init(const MemoryBuffer *MB); bool inSection(const StringRef Section, const StringRef Query) const; }; diff --git a/lib/Transforms/Utils/SpecialCaseList.cpp b/lib/Transforms/Utils/SpecialCaseList.cpp index a1083e36116..8f6802ba023 100644 --- a/lib/Transforms/Utils/SpecialCaseList.cpp +++ b/lib/Transforms/Utils/SpecialCaseList.cpp @@ -39,9 +39,17 @@ SpecialCaseList::SpecialCaseList(const StringRef Path) { EC.message()); } + init(File.get()); +} + +SpecialCaseList::SpecialCaseList(const MemoryBuffer *MB) { + init(MB); +} + +void SpecialCaseList::init(const MemoryBuffer *MB) { // Iterate through each line in the blacklist file. SmallVector Lines; - SplitString(File.take()->getBuffer(), Lines, "\n\r"); + SplitString(MB->getBuffer(), Lines, "\n\r"); StringMap Regexps; for (SmallVectorImpl::iterator I = Lines.begin(), E = Lines.end(); I != E; ++I) { -- 2.34.1