From e96196081e76c6476ae847cda11110b2c3768ee4 Mon Sep 17 00:00:00 2001 From: Brian Gaeke Date: Mon, 3 May 2004 22:06:33 +0000 Subject: In InsertProfilingInitCall(), make it legal to pass in a null array, in which case you'll get a null array and zero passed to the profiling function. llvm-svn: 13336 --- llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp') diff --git a/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp index 4cdcb9e5119..3c22b4bf42e 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilingUtils.cpp @@ -23,7 +23,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, GlobalValue *Array) { const Type *ArgVTy = PointerType::get(PointerType::get(Type::SByteTy)); - const Type *UIntPtr = PointerType::get(Type::UIntTy); + const PointerType *UIntPtr = PointerType::get(Type::UIntTy); Module &M = *MainFn->getParent(); Function *InitFn = M.getOrInsertFunction(FnName, Type::IntTy, Type::IntTy, ArgVTy, UIntPtr, Type::UIntTy, 0); @@ -39,12 +39,18 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, BasicBlock::iterator InsertPos = Entry->begin(); while (isa(InsertPos)) ++InsertPos; - ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array); std::vector GEPIndices(2, Constant::getNullValue(Type::IntTy)); - Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices); - - unsigned NumElements = - cast(Array->getType()->getElementType())->getNumElements(); + unsigned NumElements = 0; + if (Array) { + ConstantPointerRef *ArrayCPR = ConstantPointerRef::get(Array); + Args[2] = ConstantExpr::getGetElementPtr(ArrayCPR, GEPIndices); + NumElements = + cast(Array->getType()->getElementType())->getNumElements(); + } else { + // If this profiling instrumentation doesn't have a constant array, just + // pass null. + Args[2] = ConstantPointerNull::get(UIntPtr); + } Args[3] = ConstantUInt::get(Type::UIntTy, NumElements); Instruction *InitCall = new CallInst(InitFn, Args, "newargc", InsertPos); -- cgit v1.2.3