Skip to content

Commit 2840c8b

Browse files
committed
Update SanitizerCoverage.cpp
fixup....
1 parent 6b63903 commit 2840c8b

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class ModuleSanitizerCoverage {
244244
void InjectTraceForSwitch(Function &F,
245245
ArrayRef<Instruction *> SwitchTraceTargets);
246246
bool InjectCoverage(Function &F, ArrayRef<BasicBlock *> AllBlocks,
247-
Value *&FunctionGateCmp, bool IsLeafFunc = true);
247+
bool IsLeafFunc = true);
248248
GlobalVariable *CreateFunctionLocalArrayInSection(size_t NumElements,
249249
Function &F, Type *Ty,
250250
const char *Section);
@@ -725,8 +725,7 @@ void ModuleSanitizerCoverage::instrumentFunction(Function &F) {
725725
if (Options.CollectControlFlow)
726726
createFunctionControlFlow(F);
727727

728-
Value *FunctionGateCmp = nullptr;
729-
InjectCoverage(F, BlocksToInstrument, FunctionGateCmp, IsLeafFunc);
728+
InjectCoverage(F, BlocksToInstrument, IsLeafFunc);
730729
InjectCoverageForIndirectCalls(F, IndirCalls);
731730
InjectTraceForCmp(F, CmpTraceTargets);
732731
InjectTraceForSwitch(F, SwitchTraceTargets);
@@ -820,8 +819,8 @@ Value *ModuleSanitizerCoverage::CreateFunctionLocalGateCmp(IRBuilder<> &IRB) {
820819

821820
Instruction *ModuleSanitizerCoverage::CreateGateBranch(Function &F,
822821
Value *&FunctionGateCmp,
823-
Instruction *IP) {
824-
if (!FunctionGateCmp) {
822+
Instruction *IP) {
823+
if (!FunctionGateCmp) {
825824
// Create this in the entry block
826825
BasicBlock &BB = F.getEntryBlock();
827826
BasicBlock::iterator IP = BB.getFirstInsertionPt();
@@ -838,10 +837,10 @@ Instruction *ModuleSanitizerCoverage::CreateGateBranch(Function &F,
838837

839838
bool ModuleSanitizerCoverage::InjectCoverage(Function &F,
840839
ArrayRef<BasicBlock *> AllBlocks,
841-
Value *&FunctionGateCmp,
842840
bool IsLeafFunc) {
843841
if (AllBlocks.empty()) return false;
844842
CreateFunctionLocalArrays(F, AllBlocks);
843+
Value *FunctionGateCmp = nullptr;
845844
for (size_t i = 0, N = AllBlocks.size(); i < N; i++)
846845
InjectCoverageAtBlock(F, *AllBlocks[i], i, FunctionGateCmp, IsLeafFunc);
847846
return true;
@@ -1033,19 +1032,10 @@ void ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
10331032
ConstantInt::get(IntptrTy, Idx * 4)),
10341033
PtrTy);
10351034
if (Options.GatedCallbacks) {
1036-
if (!FunctionGateCmp) {
1037-
// Create this in the entry block
1038-
assert(IsEntryBB);
1039-
FunctionGateCmp = CreateFunctionLocalGateCmp(IRB);
1040-
}
1041-
// Set the branch weights in order to minimize the price paid when the
1042-
// gate is turned off, allowing the default enablement of this
1043-
// instrumentation with as little of a performance cost as possible
1044-
auto Weights = MDBuilder(*C).createBranchWeights(1, 100000);
1045-
auto ThenTerm =
1046-
SplitBlockAndInsertIfThen(FunctionGateCmp, &*IP, false, Weights);
1047-
IRBuilder<> ThenIRB(ThenTerm);
1048-
ThenIRB.CreateCall(SanCovTracePCGuard, GuardPtr)->setCannotMerge();
1035+
Instruction *I = &*IP;
1036+
auto GateBranch = CreateGateBranch(F, FunctionGateCmp, I);
1037+
IRBuilder<> GateIRB(GateBranch);
1038+
GateIRB.CreateCall(SanCovTracePCGuard, GuardPtr)->setCannotMerge();
10491039
} else {
10501040
IRB.CreateCall(SanCovTracePCGuard, GuardPtr)->setCannotMerge();
10511041
}

0 commit comments

Comments
 (0)