From ff155f03bd5d4a8fbeff09ad854582a37cdaa228 Mon Sep 17 00:00:00 2001 From: Nate Begeman Date: Thu, 15 May 2008 01:23:11 +0000 Subject: [PATCH] Move the operator new and operator delete out of line. This fixes an issue with operator new() referring to the static initTags function, which has to be in the same linkage unit as any file including User.h. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@51136 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/User.h | 19 ++----------------- lib/VMCore/Value.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/llvm/User.h b/include/llvm/User.h index 14547791548..44beac2ff89 100644 --- a/include/llvm/User.h +++ b/include/llvm/User.h @@ -227,16 +227,7 @@ protected: /// unsigned NumOperands; - void *operator new(size_t s, unsigned Us) { - void *Storage = ::operator new(s + sizeof(Use) * Us); - Use *Start = static_cast(Storage); - Use *End = Start + Us; - User *Obj = reinterpret_cast(End); - Obj->OperandList = Start; - Obj->NumOperands = Us; - Use::initTags(Start, End); - return Obj; - } + void *operator new(size_t s, unsigned Us); User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps) : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {} Use *allocHungoffUses(unsigned) const; @@ -251,13 +242,7 @@ public: ~User() { Use::zap(OperandList, OperandList + NumOperands); } - void operator delete(void *Usr) { - User *Start = static_cast(Usr); - Use *Storage = static_cast(Usr) - Start->NumOperands; - ::operator delete(Storage == Start->OperandList - ? Storage - : Usr); - } + void operator delete(void *Usr); template Use &Op() { return OperandTraits::op_begin(this)[Idx]; } diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index ff056ba74ac..919f4b00e87 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -355,3 +355,22 @@ void User::replaceUsesOfWith(Value *From, Value *To) { setOperand(i, To); // Fix it now... } } + +void *User::operator new(size_t s, unsigned Us) { + void *Storage = ::operator new(s + sizeof(Use) * Us); + Use *Start = static_cast(Storage); + Use *End = Start + Us; + User *Obj = reinterpret_cast(End); + Obj->OperandList = Start; + Obj->NumOperands = Us; + Use::initTags(Start, End); + return Obj; +} + +void User::operator delete(void *Usr) { + User *Start = static_cast(Usr); + Use *Storage = static_cast(Usr) - Start->NumOperands; + ::operator delete(Storage == Start->OperandList + ? Storage + : Usr); +}