//
// The LLVM Compiler Infrastructure
//
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
Constant *FreeFunc; // Initialized by doInitialization
bool LowerMallocArgToInteger;
public:
- static const int ID; // Pass ID, replacement for typeid
- LowerAllocations(bool LowerToInt = false)
+ static char ID; // Pass ID, replacement for typeid
+ explicit LowerAllocations(bool LowerToInt = false)
: BasicBlockPass((intptr_t)&ID), MallocFunc(0), FreeFunc(0),
LowerMallocArgToInteger(LowerToInt) {}
bool runOnBasicBlock(BasicBlock &BB);
};
- const int LowerAllocations::ID = 0;
+ char LowerAllocations::ID = 0;
RegisterPass<LowerAllocations>
X("lowerallocs", "Lower allocations from instructions to calls");
}
// This function is always successful.
//
bool LowerAllocations::doInitialization(Module &M) {
- const Type *BPTy = PointerType::get(Type::Int8Ty);
+ const Type *BPTy = PointerType::getUnqual(Type::Int8Ty);
// Prototype malloc as "char* malloc(...)", because we don't know in
// doInitialization whether size_t is int or long.
FunctionType *FT = FunctionType::get(BPTy, std::vector<const Type*>(), true);
// malloc(type) becomes sbyte *malloc(size)
Value *MallocArg;
if (LowerMallocArgToInteger)
- MallocArg = ConstantInt::get(Type::Int64Ty, TD.getTypeSize(AllocTy));
+ MallocArg = ConstantInt::get(Type::Int64Ty, TD.getABITypeSize(AllocTy));
else
MallocArg = ConstantExpr::getSizeOf(AllocTy);
MallocArg = ConstantExpr::getTruncOrBitCast(cast<Constant>(MallocArg),
Changed = true;
++NumLowered;
} else if (FreeInst *FI = dyn_cast<FreeInst>(I)) {
- Value *PtrCast = new BitCastInst(FI->getOperand(0),
- PointerType::get(Type::Int8Ty), "", I);
+ Value *PtrCast =
+ new BitCastInst(FI->getOperand(0),
+ PointerType::getUnqual(Type::Int8Ty), "", I);
// Insert a call to the free function...
(new CallInst(FreeFunc, PtrCast, "", I))->setTailCall();