[llvm-commits] CVS: llvm/lib/VMCore/BasicBlock.cpp Function.cpp Instruction.cpp Module.cpp Value.cpp
Christopher Lattner
lattner at cs.uiuc.edu
Sun Sep 8 14:00:01 PDT 2002
Changes in directory llvm/lib/VMCore:
BasicBlock.cpp updated: 1.24 -> 1.25
Function.cpp updated: 1.30 -> 1.31
Instruction.cpp updated: 1.17 -> 1.18
Module.cpp updated: 1.28 -> 1.29
Value.cpp updated: 1.26 -> 1.27
---
Log message:
Enable "garbage detection" of LLVM objects. Now users should be obnoxious
warnings. If they accidentally leak LLVM Value's.
---
Diffs of the changes:
Index: llvm/lib/VMCore/BasicBlock.cpp
diff -u llvm/lib/VMCore/BasicBlock.cpp:1.24 llvm/lib/VMCore/BasicBlock.cpp:1.25
--- llvm/lib/VMCore/BasicBlock.cpp:1.24 Fri Sep 6 16:33:15 2002
+++ llvm/lib/VMCore/BasicBlock.cpp Sun Sep 8 13:59:34 2002
@@ -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>
@@ -18,7 +19,10 @@
// 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();
@@ -56,6 +60,9 @@
// 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);
}
@@ -66,7 +73,13 @@
}
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
Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.30 llvm/lib/VMCore/Function.cpp:1.31
--- llvm/lib/VMCore/Function.cpp:1.30 Fri Sep 6 16:33:15 2002
+++ llvm/lib/VMCore/Function.cpp Sun Sep 8 13:59:35 2002
@@ -8,10 +8,14 @@
#include "llvm/Module.h"
#include "llvm/DerivedTypes.h"
#include "llvm/iOther.h"
+#include "Support/LeakDetector.h"
#include "SymbolTableListTraitsImpl.h"
BasicBlock *ilist_traits<BasicBlock>::createNode() {
- return new BasicBlock();
+ BasicBlock *Ret = new BasicBlock();
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
}
iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) {
@@ -19,7 +23,10 @@
}
Argument *ilist_traits<Argument>::createNode() {
- return new Argument(Type::IntTy);
+ Argument *Ret = new Argument(Type::IntTy);
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
}
iplist<Argument> &ilist_traits<Argument>::getList(Function *F) {
@@ -38,6 +45,10 @@
Argument::Argument(const Type *Ty, const std::string &Name = "", Function *Par)
: Value(Ty, Value::ArgumentVal, Name) {
Parent = 0;
+
+ // Make sure that we get added to a function
+ LeakDetector::addGarbageObject(this);
+
if (Par)
Par->getArgumentList().push_back(this);
}
@@ -54,7 +65,11 @@
}
void Argument::setParent(Function *parent) {
+ if (getParent())
+ LeakDetector::addGarbageObject(this);
Parent = parent;
+ if (getParent())
+ LeakDetector::removeGarbageObject(this);
}
@@ -71,6 +86,9 @@
ArgumentList.setParent(this);
ParentSymTab = SymTab = 0;
+ // Make sure that we get added to a function
+ LeakDetector::addGarbageObject(this);
+
if (ParentModule)
ParentModule->getFunctionList().push_back(this);
}
@@ -97,7 +115,11 @@
}
void Function::setParent(Module *parent) {
+ if (getParent())
+ LeakDetector::addGarbageObject(this);
Parent = parent;
+ if (getParent())
+ LeakDetector::removeGarbageObject(this);
// Relink symbol tables together...
ParentSymTab = Parent ? Parent->getSymbolTableSure() : 0;
@@ -157,12 +179,18 @@
isConstantGlobal(constant) {
if (Initializer) Operands.push_back(Use((Value*)Initializer, this));
+ LeakDetector::addGarbageObject(this);
+
if (ParentModule)
ParentModule->getGlobalList().push_back(this);
}
void GlobalVariable::setParent(Module *parent) {
+ if (getParent())
+ LeakDetector::addGarbageObject(this);
Parent = parent;
+ if (getParent())
+ LeakDetector::removeGarbageObject(this);
}
// Specialize setName to take care of symbol table majik
Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.17 llvm/lib/VMCore/Instruction.cpp:1.18
--- llvm/lib/VMCore/Instruction.cpp:1.17 Fri Sep 6 16:33:15 2002
+++ llvm/lib/VMCore/Instruction.cpp Sun Sep 8 13:59:35 2002
@@ -7,15 +7,25 @@
#include "llvm/Function.h"
#include "llvm/SymbolTable.h"
#include "llvm/Type.h"
+#include "Support/LeakDetector.h"
Instruction::Instruction(const Type *ty, unsigned it, const std::string &Name)
: User(ty, Value::InstructionVal, Name) {
Parent = 0;
iType = it;
+
+ // Make sure that we get added to a basicblock
+ LeakDetector::addGarbageObject(this);
}
void Instruction::setParent(BasicBlock *P) {
+ if (getParent())
+ LeakDetector::addGarbageObject(this);
+
Parent = P;
+
+ if (getParent())
+ LeakDetector::removeGarbageObject(this);
}
// Specialize setName to take care of symbol table majik
Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.28 llvm/lib/VMCore/Module.cpp:1.29
--- llvm/lib/VMCore/Module.cpp:1.28 Sat Aug 17 19:40:04 2002
+++ llvm/lib/VMCore/Module.cpp Sun Sep 8 13:59:35 2002
@@ -9,16 +9,24 @@
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "Support/STLExtras.h"
+#include "Support/LeakDetector.h"
#include "SymbolTableListTraitsImpl.h"
#include <algorithm>
#include <map>
Function *ilist_traits<Function>::createNode() {
- return new Function(FunctionType::get(Type::VoidTy,std::vector<const Type*>(),
- false), false);
+ FunctionType *FTy =
+ FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
+ Function *Ret = new Function(FTy, false);
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
}
GlobalVariable *ilist_traits<GlobalVariable>::createNode() {
- return new GlobalVariable(Type::IntTy, false, false);
+ GlobalVariable *Ret = new GlobalVariable(Type::IntTy, false, false);
+ // This should not be garbage monitored.
+ LeakDetector::removeGarbageObject(Ret);
+ return Ret;
}
iplist<Function> &ilist_traits<Function>::getList(Module *M) {
Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.26 llvm/lib/VMCore/Value.cpp:1.27
--- llvm/lib/VMCore/Value.cpp:1.26 Wed Jul 24 17:08:53 2002
+++ llvm/lib/VMCore/Value.cpp Sun Sep 8 13:59:35 2002
@@ -7,6 +7,7 @@
#include "llvm/InstrTypes.h"
#include "llvm/SymbolTable.h"
#include "llvm/DerivedTypes.h"
+#include "Support/LeakDetector.h"
#include <algorithm>
//===----------------------------------------------------------------------===//
@@ -39,6 +40,9 @@
}
#endif
assert(Uses.begin() == Uses.end());
+
+ // There should be no uses of this object anymore, remove it.
+ LeakDetector::removeGarbageObject(this);
}
void Value::replaceAllUsesWith(Value *D) {
More information about the llvm-commits
mailing list