From 3fc35c594cbe48070ad69eaa2fdca1e9424c9fd4 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sat, 17 Oct 2009 23:52:26 +0000 Subject: [PATCH] Fix test/Bindings/Ocaml/vmcore.ml. When IRBuilder::CreateMalloc was removed, LLVMBuildMalloc was reimplemented but with the bug that it didn't insert the resulting instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84374 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Instructions.h | 14 ++++++++------ lib/VMCore/Core.cpp | 10 ++++++---- lib/VMCore/Instructions.cpp | 23 ++++++++++++----------- test/Bindings/Ocaml/vmcore.ml | 6 +++--- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h index 438c220b2ce..373e4e3becd 100644 --- a/include/llvm/Instructions.h +++ b/include/llvm/Instructions.h @@ -992,12 +992,14 @@ public: /// constant 1. /// 2. Call malloc with that argument. /// 3. Bitcast the result of the malloc call to the specified type. - static Value *CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy, - const Type *AllocTy, Value *ArraySize = 0, - const Twine &Name = ""); - static Value *CreateMalloc(BasicBlock *InsertAtEnd, const Type *IntPtrTy, - const Type *AllocTy, Value *ArraySize = 0, - Function* MallocF = 0, const Twine &Name = ""); + static Instruction *CreateMalloc(Instruction *InsertBefore, + const Type *IntPtrTy, const Type *AllocTy, + Value *ArraySize = 0, + const Twine &Name = ""); + static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, + const Type *IntPtrTy, const Type *AllocTy, + Value *ArraySize = 0, Function* MallocF = 0, + const Twine &Name = ""); ~CallInst(); diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 5b8295f60de..d1bf0634460 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -1700,15 +1700,17 @@ LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) { LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) { const Type* IntPtrT = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext()); - return wrap(CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(), IntPtrT, - unwrap(Ty), 0, 0, Twine(Name))); + 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* IntPtrT = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext()); - return wrap(CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(), IntPtrT, - unwrap(Ty), unwrap(Val), 0, Twine(Name))); + 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 e36da135154..e212d5c542a 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -460,10 +460,10 @@ static Value *checkArraySize(Value *Amt, const Type *IntPtrTy) { return Amt; } -static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd, - const Type *IntPtrTy, const Type *AllocTy, - Value *ArraySize, Function* MallocF, - const Twine &NameStr) { +static Instruction *createMalloc(Instruction *InsertBefore, + BasicBlock *InsertAtEnd, const Type *IntPtrTy, + const Type *AllocTy, Value *ArraySize, + Function *MallocF, const Twine &NameStr) { assert(((!InsertBefore && InsertAtEnd) || (InsertBefore && !InsertAtEnd)) && "createMalloc needs either InsertBefore or InsertAtEnd"); @@ -507,7 +507,7 @@ static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd, if (!MallocF->doesNotAlias(0)) MallocF->setDoesNotAlias(0); const PointerType *AllocPtrType = PointerType::getUnqual(AllocTy); CallInst *MCall = NULL; - Value *Result = NULL; + Instruction *Result = NULL; if (InsertBefore) { MCall = CallInst::Create(MallocF, AllocSize, "malloccall", InsertBefore); Result = MCall; @@ -536,9 +536,9 @@ static Value *createMalloc(Instruction *InsertBefore, BasicBlock *InsertAtEnd, /// constant 1. /// 2. Call malloc with that argument. /// 3. Bitcast the result of the malloc call to the specified type. -Value *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy, - const Type *AllocTy, Value *ArraySize, - const Twine &Name) { +Instruction *CallInst::CreateMalloc(Instruction *InsertBefore, + const Type *IntPtrTy, const Type *AllocTy, + Value *ArraySize, const Twine &Name) { return createMalloc(InsertBefore, NULL, IntPtrTy, AllocTy, ArraySize, NULL, Name); } @@ -551,9 +551,10 @@ Value *CallInst::CreateMalloc(Instruction *InsertBefore, const Type *IntPtrTy, /// 3. Bitcast the result of the malloc call to the specified type. /// Note: This function does not add the bitcast to the basic block, that is the /// responsibility of the caller. -Value *CallInst::CreateMalloc(BasicBlock *InsertAtEnd, const Type *IntPtrTy, - const Type *AllocTy, Value *ArraySize, - Function* MallocF, const Twine &Name) { +Instruction *CallInst::CreateMalloc(BasicBlock *InsertAtEnd, + const Type *IntPtrTy, const Type *AllocTy, + Value *ArraySize, Function* MallocF, + const Twine &Name) { return createMalloc(NULL, InsertAtEnd, IntPtrTy, AllocTy, ArraySize, MallocF, Name); } diff --git a/test/Bindings/Ocaml/vmcore.ml b/test/Bindings/Ocaml/vmcore.ml index 9e976d34aa4..dd0404a9f7b 100644 --- a/test/Bindings/Ocaml/vmcore.ml +++ b/test/Bindings/Ocaml/vmcore.ml @@ -936,9 +936,9 @@ let test_builder () = group "memory"; begin let bb08 = append_block context "Bb08" fn in let b = builder_at_end context bb08 in - - (* RUN: grep {Inst20.*malloc.*i8 } < %t.ll - * RUN: grep {Inst21.*malloc.*i8.*P1} < %t.ll + + (* RUN: grep {Inst20.*malloc} < %t.ll + * RUN: grep {Inst21.*malloc} < %t.ll * RUN: grep {Inst22.*alloca.*i32 } < %t.ll * RUN: grep {Inst23.*alloca.*i32.*P2} < %t.ll * RUN: grep {free.*Inst20} < %t.ll