[Modules] Move the LeakDetector header into the IR library where the
authorChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 12:46:06 +0000 (12:46 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Tue, 4 Mar 2014 12:46:06 +0000 (12:46 +0000)
source file had already been moved. Also move the unittest into the IR
unittest library.

This may seem an odd thing to put in the IR library but we only really
use this with instructions and it needs the LLVM context to work, so it
is intrinsically tied to the IR library.

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

15 files changed:
include/llvm/IR/LeakDetector.h [new file with mode: 0644]
include/llvm/Support/LeakDetector.h [deleted file]
lib/CodeGen/MachineBasicBlock.cpp
lib/IR/BasicBlock.cpp
lib/IR/Function.cpp
lib/IR/Globals.cpp
lib/IR/Instruction.cpp
lib/IR/LeakDetector.cpp
lib/IR/Metadata.cpp
lib/IR/Module.cpp
lib/IR/Value.cpp
unittests/IR/CMakeLists.txt
unittests/IR/LeakDetectorTest.cpp [new file with mode: 0644]
unittests/Support/CMakeLists.txt
unittests/Support/LeakDetectorTest.cpp [deleted file]

diff --git a/include/llvm/IR/LeakDetector.h b/include/llvm/IR/LeakDetector.h
new file mode 100644 (file)
index 0000000..cb18df8
--- /dev/null
@@ -0,0 +1,92 @@
+//===- LeakDetector.h - Provide leak detection ------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines a class that can be used to provide very simple memory leak
+// checks for an API.  Basically LLVM uses this to make sure that Instructions,
+// for example, are deleted when they are supposed to be, and not leaked away.
+//
+// When compiling with NDEBUG (Release build), this class does nothing, thus
+// adding no checking overhead to release builds.  Note that this class is
+// implemented in a very simple way, requiring completely manual manipulation
+// and checking for garbage, but this is intentional: users should not be using
+// this API, only other APIs should.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_IR_LEAKDETECTOR_H
+#define LLVM_IR_LEAKDETECTOR_H
+
+#include <string>
+
+namespace llvm {
+
+class LLVMContext;
+class Value;
+
+struct LeakDetector {
+  /// addGarbageObject - Add a pointer to the internal set of "garbage" object
+  /// pointers.  This should be called when objects are created, or if they are
+  /// taken out of an owning collection.
+  ///
+  static void addGarbageObject(void *Object) {
+#ifndef NDEBUG
+    addGarbageObjectImpl(Object);
+#endif
+  }
+
+  /// removeGarbageObject - Remove a pointer from our internal representation of
+  /// our "garbage" objects.  This should be called when an object is added to
+  /// an "owning" collection.
+  ///
+  static void removeGarbageObject(void *Object) {
+#ifndef NDEBUG
+    removeGarbageObjectImpl(Object);
+#endif
+  }
+
+  /// checkForGarbage - Traverse the internal representation of garbage
+  /// pointers.  If there are any pointers that have been add'ed, but not
+  /// remove'd, big obnoxious warnings about memory leaks are issued.
+  ///
+  /// The specified message will be printed indicating when the check was
+  /// performed.
+  ///
+  static void checkForGarbage(LLVMContext &C, const std::string &Message) {
+#ifndef NDEBUG
+    checkForGarbageImpl(C, Message);
+#endif
+  }
+
+  /// Overload the normal methods to work better with Value*'s because they are
+  /// by far the most common in LLVM.  This does not affect the actual
+  /// functioning of this class, it just makes the warning messages nicer.
+  ///
+  static void addGarbageObject(const Value *Object) {
+#ifndef NDEBUG
+    addGarbageObjectImpl(Object);
+#endif
+  }
+  static void removeGarbageObject(const Value *Object) {
+#ifndef NDEBUG
+    removeGarbageObjectImpl(Object);
+#endif
+  }
+
+private:
+  // If we are debugging, the actual implementations will be called...
+  static void addGarbageObjectImpl(const Value *Object);
+  static void removeGarbageObjectImpl(const Value *Object);
+  static void addGarbageObjectImpl(void *Object);
+  static void removeGarbageObjectImpl(void *Object);
+  static void checkForGarbageImpl(LLVMContext &C, const std::string &Message);
+};
+
+} // End llvm namespace
+
+#endif
diff --git a/include/llvm/Support/LeakDetector.h b/include/llvm/Support/LeakDetector.h
deleted file mode 100644 (file)
index 501a9db..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-//===-- llvm/Support/LeakDetector.h - Provide leak detection ----*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines a class that can be used to provide very simple memory leak
-// checks for an API.  Basically LLVM uses this to make sure that Instructions,
-// for example, are deleted when they are supposed to be, and not leaked away.
-//
-// When compiling with NDEBUG (Release build), this class does nothing, thus
-// adding no checking overhead to release builds.  Note that this class is
-// implemented in a very simple way, requiring completely manual manipulation
-// and checking for garbage, but this is intentional: users should not be using
-// this API, only other APIs should.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_SUPPORT_LEAKDETECTOR_H
-#define LLVM_SUPPORT_LEAKDETECTOR_H
-
-#include <string>
-
-namespace llvm {
-
-class LLVMContext;
-class Value;
-
-struct LeakDetector {
-  /// addGarbageObject - Add a pointer to the internal set of "garbage" object
-  /// pointers.  This should be called when objects are created, or if they are
-  /// taken out of an owning collection.
-  ///
-  static void addGarbageObject(void *Object) {
-#ifndef NDEBUG
-    addGarbageObjectImpl(Object);
-#endif
-  }
-
-  /// removeGarbageObject - Remove a pointer from our internal representation of
-  /// our "garbage" objects.  This should be called when an object is added to
-  /// an "owning" collection.
-  ///
-  static void removeGarbageObject(void *Object) {
-#ifndef NDEBUG
-    removeGarbageObjectImpl(Object);
-#endif
-  }
-
-  /// checkForGarbage - Traverse the internal representation of garbage
-  /// pointers.  If there are any pointers that have been add'ed, but not
-  /// remove'd, big obnoxious warnings about memory leaks are issued.
-  ///
-  /// The specified message will be printed indicating when the check was
-  /// performed.
-  ///
-  static void checkForGarbage(LLVMContext &C, const std::string &Message) {
-#ifndef NDEBUG
-    checkForGarbageImpl(C, Message);
-#endif
-  }
-
-  /// Overload the normal methods to work better with Value*'s because they are
-  /// by far the most common in LLVM.  This does not affect the actual
-  /// functioning of this class, it just makes the warning messages nicer.
-  ///
-  static void addGarbageObject(const Value *Object) {
-#ifndef NDEBUG
-    addGarbageObjectImpl(Object);
-#endif
-  }
-  static void removeGarbageObject(const Value *Object) {
-#ifndef NDEBUG
-    removeGarbageObjectImpl(Object);
-#endif
-  }
-
-private:
-  // If we are debugging, the actual implementations will be called...
-  static void addGarbageObjectImpl(const Value *Object);
-  static void removeGarbageObjectImpl(const Value *Object);
-  static void addGarbageObjectImpl(void *Object);
-  static void removeGarbageObjectImpl(void *Object);
-  static void checkForGarbageImpl(LLVMContext &C, const std::string &Message);
-};
-
-} // End llvm namespace
-
-#endif
index 769ba2a..077e74d 100644 (file)
 #include "llvm/CodeGen/SlotIndexes.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetMachine.h"
index 1b1236b..ef264d2 100644 (file)
@@ -19,8 +19,8 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/IR/Type.h"
-#include "llvm/Support/LeakDetector.h"
 #include <algorithm>
 using namespace llvm;
 
index 6d418a4..72f38c5 100644 (file)
@@ -23,8 +23,8 @@
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/IntrinsicInst.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/IR/Module.h"
-#include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/RWMutex.h"
 #include "llvm/Support/StringPool.h"
index ee882c3..11152d5 100644 (file)
@@ -18,9 +18,9 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/GlobalAlias.h"
 #include "llvm/IR/GlobalVariable.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/LeakDetector.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
index a08cd9f..4bcf748 100644 (file)
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/Type.h"
-#include "llvm/Support/LeakDetector.h"
 using namespace llvm;
 
 Instruction::Instruction(Type *ty, unsigned it, Use *Ops, unsigned NumOps,
index 835e5e6..6f71627 100644 (file)
@@ -11,7 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Support/LeakDetector.h"
+#include "llvm/IR/LeakDetector.h"
 #include "LLVMContextImpl.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/IR/Value.h"
index d46eec6..f8a1776 100644 (file)
@@ -22,9 +22,9 @@
 #include "llvm/IR/ConstantRange.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ValueHandle.h"
-#include "llvm/Support/LeakDetector.h"
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
index 4204c8e..d3ef219 100644 (file)
@@ -22,7 +22,7 @@
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/LLVMContext.h"
-#include "llvm/Support/LeakDetector.h"
+#include "llvm/IR/LeakDetector.h"
 #include <algorithm>
 #include <cstdarg>
 #include <cstdlib>
index eb12bc5..bdb544b 100644 (file)
 #include "llvm/IR/GetElementPtrTypeIterator.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/LeakDetector.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/IR/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/LeakDetector.h"
 #include "llvm/Support/ManagedStatic.h"
 #include <algorithm>
 using namespace llvm;
index e1c295d..7368a24 100644 (file)
@@ -13,6 +13,7 @@ set(IRSources
   DominatorTreeTest.cpp
   IRBuilderTest.cpp
   InstructionsTest.cpp
+  LeakDetectorTest.cpp
   LegacyPassManagerTest.cpp
   MDBuilderTest.cpp
   MetadataTest.cpp
diff --git a/unittests/IR/LeakDetectorTest.cpp b/unittests/IR/LeakDetectorTest.cpp
new file mode 100644 (file)
index 0000000..94eed4c
--- /dev/null
@@ -0,0 +1,31 @@
+//===- LeakDetectorTest.cpp -----------------------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/IR/LeakDetector.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+TEST(LeakDetector, Death1) {
+  LeakDetector::addGarbageObject((void*) 1);
+  LeakDetector::addGarbageObject((void*) 2);
+
+  EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 1),
+               ".*Ts.count\\(o\\) == 0 && \"Object already in set!\"");
+  EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 2),
+               "Cache != o && \"Object already in set!\"");
+}
+#endif
+#endif
+
+}
index 9df2e17..93f707e 100644 (file)
@@ -17,7 +17,6 @@ add_llvm_unittest(SupportTests
   ErrorOrTest.cpp
   FileOutputBufferTest.cpp
   LEB128Test.cpp
-  LeakDetectorTest.cpp
   LineIteratorTest.cpp
   LockFileManagerTest.cpp
   ManagedStatic.cpp
diff --git a/unittests/Support/LeakDetectorTest.cpp b/unittests/Support/LeakDetectorTest.cpp
deleted file mode 100644 (file)
index d198c7a..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-//===- llvm/unittest/LeakDetector/LeakDetector.cpp - LeakDetector tests ---===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-#include "llvm/Support/LeakDetector.h"
-
-using namespace llvm;
-
-namespace {
-
-#ifdef GTEST_HAS_DEATH_TEST
-#ifndef NDEBUG
-TEST(LeakDetector, Death1) {
-  LeakDetector::addGarbageObject((void*) 1);
-  LeakDetector::addGarbageObject((void*) 2);
-
-  EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 1),
-               ".*Ts.count\\(o\\) == 0 && \"Object already in set!\"");
-  EXPECT_DEATH(LeakDetector::addGarbageObject((void*) 2),
-               "Cache != o && \"Object already in set!\"");
-}
-#endif
-#endif
-
-}