From: Justin Bogner Date: Mon, 28 Aug 2017 23:46:11 +0000 (+0000) Subject: [sanitizer-coverage] Return the array from CreatePCArray. NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cc308a061570ca2c8cca83a9b6527892588d5638;p=llvm [sanitizer-coverage] Return the array from CreatePCArray. NFC Be more consistent with CreateFunctionLocalArrayInSection in the API of CreatePCArray, and assign the member variable in the caller like we do for the guard and 8-bit counter arrays. This also tweaks the order of method declarations to match the order of definitions in the file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311955 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp index bac6b116e71..ffe35f57db7 100644 --- a/lib/Transforms/Instrumentation/SanitizerCoverage.cpp +++ b/lib/Transforms/Instrumentation/SanitizerCoverage.cpp @@ -204,8 +204,8 @@ private: GlobalVariable *CreateFunctionLocalArrayInSection(size_t NumElements, Function &F, Type *Ty, const char *Section); + GlobalVariable *CreatePCArray(Function &F, ArrayRef AllBlocks); void CreateFunctionLocalArrays(Function &F, ArrayRef AllBlocks); - void CreatePCArray(Function &F, ArrayRef AllBlocks); void InjectCoverageAtBlock(Function &F, BasicBlock &BB, size_t Idx); Function *CreateInitCallsForSections(Module &M, const char *InitFunctionName, Type *Ty, const char *Section); @@ -541,8 +541,9 @@ GlobalVariable *SanitizerCoverageModule::CreateFunctionLocalArrayInSection( return Array; } -void SanitizerCoverageModule::CreatePCArray(Function &F, - ArrayRef AllBlocks) { +GlobalVariable * +SanitizerCoverageModule::CreatePCArray(Function &F, + ArrayRef AllBlocks) { size_t N = AllBlocks.size(); assert(N); SmallVector PCs; @@ -559,15 +560,17 @@ void SanitizerCoverageModule::CreatePCArray(Function &F, ConstantInt::get(IntptrTy, 0), IntptrPtrTy)); } } - FunctionPCsArray = CreateFunctionLocalArrayInSection(N * 2, F, IntptrPtrTy, - SanCovPCsSectionName); - FunctionPCsArray->setInitializer( + auto *PCArray = CreateFunctionLocalArrayInSection(N * 2, F, IntptrPtrTy, + SanCovPCsSectionName); + PCArray->setInitializer( ConstantArray::get(ArrayType::get(IntptrPtrTy, N * 2), PCs)); - FunctionPCsArray->setConstant(true); + PCArray->setConstant(true); // We don't reference the PCs array in any of our runtime functions, so we // need to prevent it from being dead stripped. - appendToUsed(*F.getParent(), {FunctionPCsArray}); + appendToUsed(*F.getParent(), {PCArray}); + + return PCArray; } void SanitizerCoverageModule::CreateFunctionLocalArrays( @@ -579,7 +582,7 @@ void SanitizerCoverageModule::CreateFunctionLocalArrays( Function8bitCounterArray = CreateFunctionLocalArrayInSection( AllBlocks.size(), F, Int8Ty, SanCovCountersSectionName); if (Options.PCTable) - CreatePCArray(F, AllBlocks); + FunctionPCsArray = CreatePCArray(F, AllBlocks); } bool SanitizerCoverageModule::InjectCoverage(Function &F,