[PATCH] Introduce a GlobalList ctor which takes a MemoryBuffer to make it more unit testable, and fix memory leak in the other ctor.

Peter Collingbourne peter at pcc.me.uk
Mon Jul 8 15:35:40 PDT 2013


  Upload the right changes.

Hi samsonov, kcc,

http://llvm-reviews.chandlerc.com/D1090

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1090?vs=2723&id=2724#toc

BRANCH
  globallist2

ARCANIST PROJECT
  llvm

Files:
  include/llvm/Transforms/Utils/GlobalList.h
  lib/Transforms/Utils/GlobalList.cpp

Index: include/llvm/Transforms/Utils/GlobalList.h
===================================================================
--- include/llvm/Transforms/Utils/GlobalList.h
+++ include/llvm/Transforms/Utils/GlobalList.h
@@ -35,13 +35,16 @@
 namespace llvm {
 class Function;
 class GlobalVariable;
+class MemoryBuffer;
 class Module;
 class Regex;
 class StringRef;
 
 class GlobalList {
  public:
   GlobalList(const StringRef Path);
+  GlobalList(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 @@
  private:
   StringMap<Regex*> Entries;
 
+  void init(const MemoryBuffer *MB);
   bool inSection(const StringRef Section, const StringRef Query) const;
 };
 
Index: lib/Transforms/Utils/GlobalList.cpp
===================================================================
--- lib/Transforms/Utils/GlobalList.cpp
+++ lib/Transforms/Utils/GlobalList.cpp
@@ -39,9 +39,17 @@
                        EC.message());
   }
 
+  init(File.get());
+}
+
+GlobalList::GlobalList(const MemoryBuffer *MB) {
+  init(MB);
+}
+
+void GlobalList::init(const MemoryBuffer *MB) {
   // Iterate through each line in the blacklist file.
   SmallVector<StringRef, 16> Lines;
-  SplitString(File.take()->getBuffer(), Lines, "\n\r");
+  SplitString(MB->getBuffer(), Lines, "\n\r");
   StringMap<std::string> Regexps;
   for (SmallVector<StringRef, 16>::iterator I = Lines.begin(), E = Lines.end();
        I != E; ++I) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1090.3.patch
Type: text/x-patch
Size: 1578 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130708/009601fc/attachment.bin>


More information about the llvm-commits mailing list