diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp --- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -1046,30 +1046,25 @@ } void ModuleSanitizerCoverage::CollectFunctionControlFlow(Function &F) { - LLVM_DEBUG(dbgs() << "I am here! " << F.getName() << "\n"); SmallVector CFs; - size_t N; IRBuilder<> IRB(&*F.getEntryBlock().getFirstInsertionPt()); for (auto &BB: F) { - // blockaddress may not be used on function's entry block. + // blockaddress can not be used on function's entry block. if (&BB == &F.getEntryBlock()) CFs.push_back((Constant *)IRB.CreatePointerCast(&F, IntptrPtrTy)); else CFs.push_back((Constant *)IRB.CreatePointerCast(BlockAddress::get(&BB), IntptrPtrTy)); for (auto SuccBB : successors(&BB)) { - if (SuccBB == &F.getEntryBlock()) - CFs.push_back((Constant *)IRB.CreatePointerCast(&F, IntptrPtrTy)); - else - CFs.push_back((Constant *)IRB.CreatePointerCast(BlockAddress::get(SuccBB), IntptrPtrTy)); + assert(SuccBB != &F.getEntryBlock()); + CFs.push_back((Constant *)IRB.CreatePointerCast(BlockAddress::get(SuccBB), IntptrPtrTy)); } CFs.push_back((Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 0), IntptrPtrTy)); for (auto &Inst: BB) { - CallBase *CB = dyn_cast(&Inst); - if (CB) { + if (CallBase *CB = dyn_cast(&Inst)) { if (!CB->isIndirectCall()) { auto CalledF = CB->getCalledFunction(); if (CalledF && !CalledF->isIntrinsic()) @@ -1082,7 +1077,7 @@ CFs.push_back((Constant *)IRB.CreateIntToPtr(ConstantInt::get(IntptrTy, 0), IntptrPtrTy)); } - N = CFs.size(); + size_t N = CFs.size(); auto CFArray = CreateFunctionLocalArrayInSection(N, F, IntptrPtrTy, SanCovCFsSectionName); CFArray->setInitializer(ConstantArray::get(ArrayType::get(IntptrPtrTy, N), CFs)); CFArray->setConstant(true);