Skip to content

Commit 2a16328

Browse files
authored
[tysan] Convert TySan from function+module pass to just module pass (#120667)
As mentioned in #118989, all sanitizers but tsan are converted to just module pass for easier maintenance. This patch removes the TySan function pass, convert TySan from function+module pass to just module pass.
1 parent b253a80 commit 2a16328

File tree

17 files changed

+29
-39
lines changed

17 files changed

+29
-39
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,8 @@ static void addSanitizers(const Triple &TargetTriple,
736736
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
737737
}
738738

739-
if (LangOpts.Sanitize.has(SanitizerKind::Type)) {
740-
MPM.addPass(ModuleTypeSanitizerPass());
741-
MPM.addPass(createModuleToFunctionPassAdaptor(TypeSanitizerPass()));
742-
}
739+
if (LangOpts.Sanitize.has(SanitizerKind::Type))
740+
MPM.addPass(TypeSanitizerPass());
743741

744742
if (LangOpts.Sanitize.has(SanitizerKind::NumericalStability))
745743
MPM.addPass(NumericalStabilitySanitizerPass());

llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,11 @@ class Function;
2020
class FunctionPass;
2121
class Module;
2222

23-
/// A function pass for tysan instrumentation.
2423
struct TypeSanitizerPass : public PassInfoMixin<TypeSanitizerPass> {
25-
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
26-
static bool isRequired() { return true; }
27-
};
28-
29-
/// A module pass for tysan instrumentation.
30-
///
31-
/// Create ctor and init functions.
32-
struct ModuleTypeSanitizerPass : public PassInfoMixin<ModuleTypeSanitizerPass> {
3324
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
3425
static bool isRequired() { return true; }
3526
};
3627

3728
} // namespace llvm
29+
3830
#endif /* LLVM_TRANSFORMS_INSTRUMENTATION_TYPESANITIZER_H */

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
156156
MODULE_PASS("trigger-crash-module", TriggerCrashModulePass())
157157
MODULE_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
158158
MODULE_PASS("tsan-module", ModuleThreadSanitizerPass())
159-
MODULE_PASS("tysan-module", ModuleTypeSanitizerPass())
159+
MODULE_PASS("tysan", TypeSanitizerPass())
160160
MODULE_PASS("verify", VerifierPass())
161161
MODULE_PASS("view-callgraph", CallGraphViewerPass())
162162
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass())
@@ -481,7 +481,6 @@ FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
481481
FUNCTION_PASS("trigger-crash-function", TriggerCrashFunctionPass())
482482
FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
483483
FUNCTION_PASS("tsan", ThreadSanitizerPass())
484-
FUNCTION_PASS("tysan", TypeSanitizerPass())
485484
FUNCTION_PASS("typepromotion", TypePromotionPass(TM))
486485
FUNCTION_PASS("unify-loop-exits", UnifyLoopExitsPass())
487486
FUNCTION_PASS("vector-combine", VectorCombinePass())

llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace {
7070
/// violations.
7171
struct TypeSanitizer {
7272
TypeSanitizer(Module &M);
73-
bool run(Function &F, const TargetLibraryInfo &TLI);
73+
bool sanitizeFunction(Function &F, const TargetLibraryInfo &TLI);
7474
void instrumentGlobals(Module &M);
7575

7676
private:
@@ -510,7 +510,8 @@ void collectMemAccessInfo(
510510
}
511511
}
512512

513-
bool TypeSanitizer::run(Function &F, const TargetLibraryInfo &TLI) {
513+
bool TypeSanitizer::sanitizeFunction(Function &F,
514+
const TargetLibraryInfo &TLI) {
514515
// This is required to prevent instrumenting call to __tysan_init from within
515516
// the module constructor.
516517
if (&F == TysanCtorFunction.getCallee() || &F == TysanGlobalsSetTypeFunction)
@@ -876,15 +877,8 @@ bool TypeSanitizer::instrumentMemInst(Value *V, Instruction *ShadowBase,
876877
return true;
877878
}
878879

879-
PreservedAnalyses TypeSanitizerPass::run(Function &F,
880-
FunctionAnalysisManager &FAM) {
881-
TypeSanitizer TySan(*F.getParent());
882-
TySan.run(F, FAM.getResult<TargetLibraryAnalysis>(F));
883-
return PreservedAnalyses::none();
884-
}
885-
886-
PreservedAnalyses ModuleTypeSanitizerPass::run(Module &M,
887-
ModuleAnalysisManager &AM) {
880+
PreservedAnalyses TypeSanitizerPass::run(Module &M,
881+
ModuleAnalysisManager &MAM) {
888882
Function *TysanCtorFunction;
889883
std::tie(TysanCtorFunction, std::ignore) =
890884
createSanitizerCtorAndInitFunctions(M, kTysanModuleCtorName,
@@ -894,5 +888,12 @@ PreservedAnalyses ModuleTypeSanitizerPass::run(Module &M,
894888
TypeSanitizer TySan(M);
895889
TySan.instrumentGlobals(M);
896890
appendToGlobalCtors(M, TysanCtorFunction, 0);
891+
892+
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
893+
for (Function &F : M) {
894+
const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
895+
TySan.sanitizeFunction(F, TLI);
896+
}
897+
897898
return PreservedAnalyses::none();
898899
}

llvm/test/Instrumentation/TypeSanitizer/access-with-offset.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
2+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
33

44
;.
55
; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @tysan.module_ctor, ptr null }]

llvm/test/Instrumentation/TypeSanitizer/alloca-only.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/alloca.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/anon.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/basic-nosan.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --include-generated-funcs
22
; Test basic type sanitizer instrumentation.
3-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
3+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
44

55
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
66

llvm/test/Instrumentation/TypeSanitizer/basic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/byval.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --include-generated-funcs
22
; Test basic type sanitizer instrumentation.
3-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
3+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
44

55
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
66

llvm/test/Instrumentation/TypeSanitizer/globals.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals --include-generated-funcs
2-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
2+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
33

44
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
55

llvm/test/Instrumentation/TypeSanitizer/invalid-metadata.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals --include-generated-funcs
2-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
2+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
33

44
!llvm.tysan.globals = !{!0}
55

llvm/test/Instrumentation/TypeSanitizer/memintrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/nosanitize.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/sanitize-no-tbaa.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

llvm/test/Instrumentation/TypeSanitizer/swifterror.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; Test basic type sanitizer instrumentation.
33
;
4-
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
4+
; RUN: opt -passes='tysan' -S %s | FileCheck %s
55

66
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
77

0 commit comments

Comments
 (0)