Another portability fix provided via Casey Carter:
[oota-llvm.git] / lib / VMCore / BasicBlock.cpp
index d0859f874322e1123155bbab1c432e57c1343433..bf7191c659328fa5435731abd9cf756c277f0e4a 100644 (file)
@@ -1,4 +1,4 @@
-//===-- BasicBlock.cpp - Implement BasicBlock related functions --*- C++ -*--=//
+//===-- BasicBlock.cpp - Implement BasicBlock related methods -------------===//
 //
 // This file implements the BasicBlock class for the VMCore library.
 //
@@ -11,6 +11,7 @@
 #include "llvm/Constant.h"
 #include "llvm/iPHINode.h"
 #include "llvm/SymbolTable.h"
+#include "Support/LeakDetector.h"
 #include "SymbolTableListTraitsImpl.h"
 #include <algorithm>
 
 // instruction list.  This is not a real instruction.
 //
 struct DummyInst : public Instruction {
-  DummyInst() : Instruction(Type::VoidTy, NumOtherOps) {}
+  DummyInst() : Instruction(Type::VoidTy, NumOtherOps) {
+    // This should not be garbage monitored.
+    LeakDetector::removeGarbageObject(this);
+  }
 
   virtual Instruction *clone() const {
     assert(0 && "Cannot clone EOL");abort();
@@ -48,11 +52,17 @@ iplist<Instruction> &ilist_traits<Instruction>::getList(BasicBlock *BB) {
 template SymbolTableListTraits<Instruction, BasicBlock, Function>;
 
 
+// BasicBlock ctor - If the function parameter is specified, the basic block is
+// automatically inserted at the end of the function.
+//
 BasicBlock::BasicBlock(const std::string &name, Function *Parent)
   : Value(Type::LabelTy, Value::BasicBlockVal, name) {
   // Initialize the instlist...
   InstList.setItemParent(this);
 
+  // Make sure that we get added to a function
+  LeakDetector::addGarbageObject(this);
+
   if (Parent)
     Parent->getBasicBlockList().push_back(this);
 }
@@ -62,6 +72,16 @@ BasicBlock::~BasicBlock() {
   InstList.clear();
 }
 
+void BasicBlock::setParent(Function *parent) {
+  if (getParent())
+    LeakDetector::addGarbageObject(this);
+
+  InstList.setParent(parent);
+
+  if (getParent())
+    LeakDetector::removeGarbageObject(this);
+}
+
 // Specialize setName to take care of symbol table majik
 void BasicBlock::setName(const std::string &name, SymbolTable *ST) {
   Function *P;