Skip to content

Commit e29996c

Browse files
thejhramosian-glider
authored andcommitted
[AddressSanitizer] Refactor ClDebug{Min,Max} handling
Summary: A following commit will split the loop over ToInstrument into two. To avoid having to duplicate the condition for suppressing instrumentation sites based on ClDebug{Min,Max}, refactor it out into a new function. While we're at it, we can also avoid the indirection through NumInstrumented for setting FunctionModified. This is patch 1/4 of a patch series: https://reviews.llvm.org/D77616 [PATCH 1/4] [AddressSanitizer] Refactor ClDebug{Min,Max} handling https://reviews.llvm.org/D77617 [PATCH 2/4] [AddressSanitizer] Split out memory intrinsic handling https://reviews.llvm.org/D77618 [PATCH 3/4] [AddressSanitizer] Refactor: Permit >1 interesting operands per instruction https://reviews.llvm.org/D77619 [PATCH 4/4] [AddressSanitizer] Instrument byval call arguments Reviewers: kcc, glider Reviewed By: glider Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77616
1 parent 31db4db commit e29996c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ struct AddressSanitizer {
638638
Value *SizeArgument, uint32_t Exp);
639639
void instrumentMemIntrinsic(MemIntrinsic *MI);
640640
Value *memToShadow(Value *Shadow, IRBuilder<> &IRB);
641+
bool suppressInstrumentationSiteForDebug(int &Instrumented);
641642
bool instrumentFunction(Function &F, const TargetLibraryInfo *TLI);
642643
bool maybeInsertAsanInitAtFunctionEntry(Function &F);
643644
void maybeInsertDynamicShadowAtFunctionEntry(Function &F);
@@ -2610,6 +2611,14 @@ void AddressSanitizer::markEscapedLocalAllocas(Function &F) {
26102611
}
26112612
}
26122613

2614+
bool AddressSanitizer::suppressInstrumentationSiteForDebug(int &Instrumented) {
2615+
bool ShouldInstrument =
2616+
ClDebugMin < 0 || ClDebugMax < 0 ||
2617+
(Instrumented >= ClDebugMin && Instrumented <= ClDebugMax);
2618+
Instrumented++;
2619+
return !ShouldInstrument;
2620+
}
2621+
26132622
bool AddressSanitizer::instrumentFunction(Function &F,
26142623
const TargetLibraryInfo *TLI) {
26152624
if (F.getLinkage() == GlobalValue::AvailableExternallyLinkage) return false;
@@ -2710,15 +2719,14 @@ bool AddressSanitizer::instrumentFunction(Function &F,
27102719
// Instrument.
27112720
int NumInstrumented = 0;
27122721
for (auto Inst : ToInstrument) {
2713-
if (ClDebugMin < 0 || ClDebugMax < 0 ||
2714-
(NumInstrumented >= ClDebugMin && NumInstrumented <= ClDebugMax)) {
2722+
if (!suppressInstrumentationSiteForDebug(NumInstrumented)) {
27152723
if (isInterestingMemoryAccess(Inst, &IsWrite, &TypeSize, &Alignment))
27162724
instrumentMop(ObjSizeVis, Inst, UseCalls,
27172725
F.getParent()->getDataLayout());
27182726
else
27192727
instrumentMemIntrinsic(cast<MemIntrinsic>(Inst));
27202728
}
2721-
NumInstrumented++;
2729+
FunctionModified = true;
27222730
}
27232731

27242732
FunctionStackPoisoner FSP(F, *this);
@@ -2733,10 +2741,10 @@ bool AddressSanitizer::instrumentFunction(Function &F,
27332741

27342742
for (auto Inst : PointerComparisonsOrSubtracts) {
27352743
instrumentPointerComparisonOrSubtraction(Inst);
2736-
NumInstrumented++;
2744+
FunctionModified = true;
27372745
}
27382746

2739-
if (NumInstrumented > 0 || ChangedStack || !NoReturnCalls.empty())
2747+
if (ChangedStack || !NoReturnCalls.empty())
27402748
FunctionModified = true;
27412749

27422750
LLVM_DEBUG(dbgs() << "ASAN done instrumenting: " << FunctionModified << " "

0 commit comments

Comments
 (0)