From df98761d08ae091420b7e9c1366de7684400fc36 Mon Sep 17 00:00:00 2001 From: Victor Hernandez Date: Fri, 6 Nov 2009 01:33:24 +0000 Subject: Revert r86077 because it caused crashes in 179.art and 175.vpr on ARM git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86213 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Core.cpp | 22 ++++++++-------------- lib/VMCore/Instructions.cpp | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 34 deletions(-) (limited to 'lib/VMCore') diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 1a34180..9a49d42 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -1699,24 +1699,18 @@ LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) { - const Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext()); - Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty)); - AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy); - Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(), - ITy, unwrap(Ty), AllocSize, - 0, 0, ""); - return wrap(unwrap(B)->Insert(Malloc, Twine(Name))); + const Type* IntPtrT = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext()); + return wrap(unwrap(B)->Insert(CallInst::CreateMalloc( + unwrap(B)->GetInsertBlock(), IntPtrT, unwrap(Ty), 0, 0, ""), + Twine(Name))); } LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Val, const char *Name) { - const Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext()); - Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty)); - AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy); - Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(), - ITy, unwrap(Ty), AllocSize, - unwrap(Val), 0, ""); - return wrap(unwrap(B)->Insert(Malloc, Twine(Name))); + const Type* IntPtrT = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext()); + return wrap(unwrap(B)->Insert(CallInst::CreateMalloc( + unwrap(B)->GetInsertBlock(), IntPtrT, unwrap(Ty), unwrap(Val), 0, ""), + Twine(Name))); } LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty, diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 279bc73..52d8735 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -24,7 +24,6 @@ #include "llvm/Support/CallSite.h" #include "llvm/Support/ConstantRange.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Target/TargetData.h" using namespace llvm; @@ -449,11 +448,22 @@ static bool IsConstantOne(Value *val) { return isa(val) && cast(val)->isOne(); } +static Value *checkArraySize(Value *Amt, const Type *IntPtrTy) { + if (!Amt) + Amt = ConstantInt::get(IntPtrTy, 1); + else { + assert(!isa(Amt) && + "Passed basic block into malloc size parameter! Use other ctor"); + assert(Amt->getType() == IntPtrTy && + "Malloc array size is not an intptr!"); + } + return Amt; +} + static Instruction *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd, const Type *IntPtrTy, - const Type *AllocTy, Value *AllocSize, - Value *ArraySize, Function *MallocF, - const Twine &Name) { + const Type *AllocTy, Value *ArraySize, + Function *MallocF, const Twine &NameStr) { assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && "createMalloc needs either InsertBefore or InsertAtEnd"); @@ -461,14 +471,10 @@ static Instruction *createMalloc(Instruction *InsertBefore, // bitcast (i8* malloc(typeSize)) to type* // malloc(type, arraySize) becomes: // bitcast (i8 *malloc(typeSize*arraySize)) to type* - if (!ArraySize) - ArraySize = ConstantInt::get(IntPtrTy, 1); - else if (ArraySize->getType() != IntPtrTy) { - if (InsertBefore) - ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy, false, "", InsertBefore); - else - ArraySize = CastInst::CreateIntegerCast(ArraySize, IntPtrTy, false, "", InsertAtEnd); - } + Value *AllocSize = ConstantExpr::getSizeOf(AllocTy); + AllocSize = ConstantExpr::getTruncOrBitCast(cast(AllocSize), + IntPtrTy); + ArraySize = checkArraySize(ArraySize, IntPtrTy); if (!IsConstantOne(ArraySize)) { if (IsConstantOne(AllocSize)) { @@ -507,14 +513,14 @@ static Instruction *createMalloc(Instruction *InsertBefore, Result = MCall; if (Result->getType() != AllocPtrType) // Create a cast instruction to convert to the right type... - Result = new BitCastInst(MCall, AllocPtrType, Name, InsertBefore); + Result = new BitCastInst(MCall, AllocPtrType, NameStr, InsertBefore); } else { MCall = CallInst::Create(MallocF, AllocSize, "malloccall"); Result = MCall; if (Result->getType() != AllocPtrType) { InsertAtEnd->getInstList().push_back(MCall); // Create a cast instruction to convert to the right type... - Result = new BitCastInst(MCall, AllocPtrType, Name); + Result = new BitCastInst(MCall, AllocPtrType, NameStr); } } MCall->setTailCall(); @@ -532,9 +538,8 @@ static Instruction *createMalloc(Instruction *InsertBefore, /// 3. Bitcast the result of the malloc call to the specified type. Instruction *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy, const Type *AllocTy, - Value *AllocSize, Value *ArraySize, - const Twine &Name) { - return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, AllocSize, + Value *ArraySize, const Twine &Name) { + return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, ArraySize, NULL, Name); } @@ -548,9 +553,9 @@ Instruction *CallInst::CreateMalloc(Instruction *InsertBefore, /// responsibility of the caller. Instruction *CallInst::CreateMalloc(BasicBlock *InsertAtEnd, const Type *IntPtrTy, const Type *AllocTy, - Value *AllocSize, Value *ArraySize, - Function *MallocF, const Twine &Name) { - return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy, AllocSize, + Value *ArraySize, Function* MallocF, + const Twine &Name) { + return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy, ArraySize, MallocF, Name); } -- cgit v1.1