Skip to content

Commit c50ca98

Browse files
committed
[SIL] Factor out logic for detecting sanitizer instrumentation. NFC.
Factor out common logic for detecting sanitizer instrumentation and put it in SIL/InstructionUtils.
1 parent 60f2002 commit c50ca98

File tree

4 files changed

+19
-32
lines changed

4 files changed

+19
-32
lines changed

include/swift/SIL/InstructionUtils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ bool isIncidentalUse(SILInstruction *user);
111111
/// only used in recognizable patterns without otherwise "escaping".
112112
bool onlyAffectsRefCount(SILInstruction *user);
113113

114+
/// Return true when the instruction represents added instrumentation for
115+
/// run-time sanitizers.
116+
bool isSanitizerInstrumentation(SILInstruction *Instruction);
117+
114118
/// If V is a convert_function or convert_escape_to_noescape return its operand
115119
/// recursively.
116120
SILValue stripConvertFunctions(SILValue V);

lib/SIL/InstructionUtils.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ bool swift::onlyAffectsRefCount(SILInstruction *user) {
299299
}
300300
}
301301

302+
bool swift::isSanitizerInstrumentation(SILInstruction *Instruction) {
303+
auto *BI = dyn_cast<BuiltinInst>(Instruction);
304+
if (!BI)
305+
return false;
306+
307+
Identifier Name = BI->getName();
308+
if (Name == BI->getModule().getASTContext().getIdentifier("tsanInoutAccess"))
309+
return true;
310+
311+
return false;
312+
}
313+
302314
SILValue swift::stripConvertFunctions(SILValue V) {
303315
while (true) {
304316
if (auto CFI = dyn_cast<ConvertFunctionInst>(V)) {

lib/SILOptimizer/Mandatory/DIMemoryUseCollectorOwnership.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -683,21 +683,6 @@ static SILValue getAccessedPointer(SILValue Pointer) {
683683
return Pointer;
684684
}
685685

686-
/// Returns true when the instruction represents added instrumentation for
687-
/// run-time sanitizers.
688-
static bool isSanitizerInstrumentation(SILInstruction *Instruction,
689-
ASTContext &Ctx) {
690-
auto *BI = dyn_cast<BuiltinInst>(Instruction);
691-
if (!BI)
692-
return false;
693-
694-
Identifier Name = BI->getName();
695-
if (Name == Ctx.getIdentifier("tsanInoutAccess"))
696-
return true;
697-
698-
return false;
699-
}
700-
701686
void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
702687
assert(Pointer->getType().isAddress() &&
703688
"Walked through the pointer to the value?");
@@ -954,7 +939,7 @@ void ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
954939

955940
// Sanitizer instrumentation is not user visible, so it should not
956941
// count as a use and must not affect compile-time diagnostics.
957-
if (isSanitizerInstrumentation(User, Module.getASTContext()))
942+
if (isSanitizerInstrumentation(User))
958943
continue;
959944

960945
// Otherwise, the use is something complicated, it escapes.

lib/SILOptimizer/Mandatory/PMOMemoryUseCollector.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define DEBUG_TYPE "definite-init"
1414
#include "PMOMemoryUseCollector.h"
1515
#include "swift/AST/Expr.h"
16+
#include "swift/SIL/InstructionUtils.h"
1617
#include "swift/SIL/SILArgument.h"
1718
#include "swift/SIL/SILBuilder.h"
1819
#include "llvm/ADT/StringExtras.h"
@@ -364,21 +365,6 @@ bool ElementUseCollector::collectContainerUses(AllocBoxInst *ABI) {
364365
return true;
365366
}
366367

367-
// Returns true when the instruction represents added instrumentation for
368-
/// run-time sanitizers.
369-
static bool isSanitizerInstrumentation(SILInstruction *Instruction,
370-
ASTContext &Ctx) {
371-
auto *BI = dyn_cast<BuiltinInst>(Instruction);
372-
if (!BI)
373-
return false;
374-
375-
Identifier Name = BI->getName();
376-
if (Name == Ctx.getIdentifier("tsanInoutAccess"))
377-
return true;
378-
379-
return false;
380-
}
381-
382368
bool ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
383369
assert(Pointer->getType().isAddress() &&
384370
"Walked through the pointer to the value?");
@@ -630,7 +616,7 @@ bool ElementUseCollector::collectUses(SILValue Pointer, unsigned BaseEltNo) {
630616

631617
// Sanitizer instrumentation is not user visible, so it should not
632618
// count as a use and must not affect compile-time diagnostics.
633-
if (isSanitizerInstrumentation(User, Module.getASTContext()))
619+
if (isSanitizerInstrumentation(User))
634620
continue;
635621

636622
// Otherwise, the use is something complicated, it escapes.

0 commit comments

Comments
 (0)