- ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal));
- ptr_arr = builder->CreateMalloc(IntegerType::Int8Ty, val_mem, "arr");
-
- //call void @llvm.memset.i32(i8 *%arr, i8 0, i32 %d, i32 1)
+ ConstantInt *val_mem = ConstantInt::get(C, APInt(32, memtotal));
+ BasicBlock* BB = builder->GetInsertBlock();
+ Type* IntPtrTy = IntegerType::getInt32Ty(C);
+ Type* Int8Ty = IntegerType::getInt8Ty(C);
+ Constant* allocsize = ConstantExpr::getSizeOf(Int8Ty);
+ allocsize = ConstantExpr::getTruncOrBitCast(allocsize, IntPtrTy);
+ ptr_arr = CallInst::CreateMalloc(BB, IntPtrTy, Int8Ty, allocsize, val_mem,
+ NULL, "arr");
+ BB->getInstList().push_back(cast<Instruction>(ptr_arr));
+
+ //call void @llvm.memset.p0i8.i32(i8 *%arr, i8 0, i32 %d, i32 1, i1 0)