aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/Function.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-08 18:59:35 +0000
committerChris Lattner <sabre@nondot.org>2002-09-08 18:59:35 +0000
commitd1e693f2a3883dacf213aa2b477540c57b53b714 (patch)
tree46b79948a66f3765a515c8cccaf2f7995a29c8ce /lib/VMCore/Function.cpp
parentbd78696719a77c0ab4876901f2fa4dcbed234e46 (diff)
Enable "garbage detection" of LLVM objects. Now users should be obnoxious
warnings. If they accidentally leak LLVM Value's. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3620 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Function.cpp')
-rw-r--r--lib/VMCore/Function.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 59017178f6..fb940bf804 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -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 @@ iplist<BasicBlock> &ilist_traits<BasicBlock>::getList(Function *F) {
}
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 @@ template SymbolTableListTraits<BasicBlock, Function, Function>;
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::setName(const std::string &name, SymbolTable *ST) {
}
void Argument::setParent(Function *parent) {
+ if (getParent())
+ LeakDetector::addGarbageObject(this);
Parent = parent;
+ if (getParent())
+ LeakDetector::removeGarbageObject(this);
}
@@ -71,6 +86,9 @@ Function::Function(const FunctionType *Ty, bool isInternal,
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::setName(const std::string &name, SymbolTable *ST) {
}
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 @@ GlobalVariable::GlobalVariable(const Type *Ty, bool constant, bool isIntern,
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