Skip to content

Commit 2326be0

Browse files
committed
optimization: disable catch-parameter instrumentation via a linear pass over function basic blocks
1 parent 043848d commit 2326be0

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ struct AddressSanitizer {
847847
bool maybeInsertAsanInitAtFunctionEntry(Function &F);
848848
bool maybeInsertDynamicShadowAtFunctionEntry(Function &F);
849849
void markEscapedLocalAllocas(Function &F);
850+
void markCatchParametersAsUninteresting(Function &F);
850851

851852
private:
852853
friend struct FunctionStackPoisoner;
@@ -1397,16 +1398,6 @@ void AddressSanitizer::instrumentMemIntrinsic(MemIntrinsic *MI,
13971398
MI->eraseFromParent();
13981399
}
13991400

1400-
// Check if an alloca is a catch block parameter
1401-
static bool isCatchParameter(const AllocaInst &AI) {
1402-
for (const Use &U : AI.uses()) {
1403-
if (isa<CatchPadInst>(U.getUser())) {
1404-
return true;
1405-
}
1406-
}
1407-
return false;
1408-
}
1409-
14101401
/// Check if we want (and can) handle this alloca.
14111402
bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
14121403
auto [It, Inserted] = ProcessedAllocas.try_emplace(&AI);
@@ -1427,11 +1418,7 @@ bool AddressSanitizer::isInterestingAlloca(const AllocaInst &AI) {
14271418
// swifterror allocas are register promoted by ISel
14281419
!AI.isSwiftError() &&
14291420
// safe allocas are not interesting
1430-
!(SSGI && SSGI->isSafe(AI)) &&
1431-
// Mitigation for https://github.com/google/sanitizers/issues/749
1432-
// We don't instrument Windows catch-block parameters to avoid
1433-
// interfering with exception handling assumptions.
1434-
!(TargetTriple.isOSWindows() && isCatchParameter(AI)));
1421+
!(SSGI && SSGI->isSafe(AI)));
14351422

14361423
It->second = IsInteresting;
14371424
return IsInteresting;
@@ -2989,6 +2976,24 @@ void AddressSanitizer::markEscapedLocalAllocas(Function &F) {
29892976
}
29902977
}
29912978
}
2979+
// Mitigation for https://github.com/google/sanitizers/issues/749
2980+
// We don't instrument Windows catch-block parameters to avoid
2981+
// interfering with exception handling assumptions.
2982+
void AddressSanitizer::markCatchParametersAsUninteresting(Function &F) {
2983+
for (BasicBlock &BB : F) {
2984+
for (Instruction &I : BB) {
2985+
if (auto *CatchPad = dyn_cast<CatchPadInst>(&I)) {
2986+
// Mark the parameters to a catch-block as uninteresting to avoid
2987+
// instrumenting them
2988+
for (Value *Operand : CatchPad->arg_operands()) {
2989+
if (auto *AI = dyn_cast<AllocaInst>(Operand)) {
2990+
ProcessedAllocas[AI] = false;
2991+
}
2992+
}
2993+
}
2994+
}
2995+
}
2996+
}
29922997

29932998
bool AddressSanitizer::suppressInstrumentationSiteForDebug(int &Instrumented) {
29942999
bool ShouldInstrument =
@@ -3032,6 +3037,9 @@ bool AddressSanitizer::instrumentFunction(Function &F,
30323037
// can be passed to that intrinsic.
30333038
markEscapedLocalAllocas(F);
30343039

3040+
if (TargetTriple.isOSWindows())
3041+
markCatchParametersAsUninteresting(F);
3042+
30353043
// We want to instrument every address only once per basic block (unless there
30363044
// are calls between uses).
30373045
SmallPtrSet<Value *, 16> TempsToInstrument;

0 commit comments

Comments
 (0)