mirror of
https://github.com/intel/llvm.git
synced 2026-02-05 13:21:04 +08:00
[tysan] Convert TySan from function+module pass to just module pass (#120667)
As mentioned in https://github.com/llvm/llvm-project/pull/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.
This commit is contained in:
@@ -736,10 +736,8 @@ static void addSanitizers(const Triple &TargetTriple,
|
||||
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
|
||||
}
|
||||
|
||||
if (LangOpts.Sanitize.has(SanitizerKind::Type)) {
|
||||
MPM.addPass(ModuleTypeSanitizerPass());
|
||||
MPM.addPass(createModuleToFunctionPassAdaptor(TypeSanitizerPass()));
|
||||
}
|
||||
if (LangOpts.Sanitize.has(SanitizerKind::Type))
|
||||
MPM.addPass(TypeSanitizerPass());
|
||||
|
||||
if (LangOpts.Sanitize.has(SanitizerKind::NumericalStability))
|
||||
MPM.addPass(NumericalStabilitySanitizerPass());
|
||||
|
||||
@@ -20,19 +20,11 @@ class Function;
|
||||
class FunctionPass;
|
||||
class Module;
|
||||
|
||||
/// A function pass for tysan instrumentation.
|
||||
struct TypeSanitizerPass : public PassInfoMixin<TypeSanitizerPass> {
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
|
||||
static bool isRequired() { return true; }
|
||||
};
|
||||
|
||||
/// A module pass for tysan instrumentation.
|
||||
///
|
||||
/// Create ctor and init functions.
|
||||
struct ModuleTypeSanitizerPass : public PassInfoMixin<ModuleTypeSanitizerPass> {
|
||||
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
|
||||
static bool isRequired() { return true; }
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif /* LLVM_TRANSFORMS_INSTRUMENTATION_TYPESANITIZER_H */
|
||||
|
||||
@@ -156,7 +156,7 @@ MODULE_PASS("strip-nonlinetable-debuginfo", StripNonLineTableDebugInfoPass())
|
||||
MODULE_PASS("trigger-crash-module", TriggerCrashModulePass())
|
||||
MODULE_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
|
||||
MODULE_PASS("tsan-module", ModuleThreadSanitizerPass())
|
||||
MODULE_PASS("tysan-module", ModuleTypeSanitizerPass())
|
||||
MODULE_PASS("tysan", TypeSanitizerPass())
|
||||
MODULE_PASS("verify", VerifierPass())
|
||||
MODULE_PASS("view-callgraph", CallGraphViewerPass())
|
||||
MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass())
|
||||
@@ -481,7 +481,6 @@ FUNCTION_PASS("transform-warning", WarnMissedTransformationsPass())
|
||||
FUNCTION_PASS("trigger-crash-function", TriggerCrashFunctionPass())
|
||||
FUNCTION_PASS("trigger-verifier-error", TriggerVerifierErrorPass())
|
||||
FUNCTION_PASS("tsan", ThreadSanitizerPass())
|
||||
FUNCTION_PASS("tysan", TypeSanitizerPass())
|
||||
FUNCTION_PASS("typepromotion", TypePromotionPass(TM))
|
||||
FUNCTION_PASS("unify-loop-exits", UnifyLoopExitsPass())
|
||||
FUNCTION_PASS("vector-combine", VectorCombinePass())
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace {
|
||||
/// violations.
|
||||
struct TypeSanitizer {
|
||||
TypeSanitizer(Module &M);
|
||||
bool run(Function &F, const TargetLibraryInfo &TLI);
|
||||
bool sanitizeFunction(Function &F, const TargetLibraryInfo &TLI);
|
||||
void instrumentGlobals(Module &M);
|
||||
|
||||
private:
|
||||
@@ -510,7 +510,8 @@ void collectMemAccessInfo(
|
||||
}
|
||||
}
|
||||
|
||||
bool TypeSanitizer::run(Function &F, const TargetLibraryInfo &TLI) {
|
||||
bool TypeSanitizer::sanitizeFunction(Function &F,
|
||||
const TargetLibraryInfo &TLI) {
|
||||
// This is required to prevent instrumenting call to __tysan_init from within
|
||||
// the module constructor.
|
||||
if (&F == TysanCtorFunction.getCallee() || &F == TysanGlobalsSetTypeFunction)
|
||||
@@ -876,15 +877,8 @@ bool TypeSanitizer::instrumentMemInst(Value *V, Instruction *ShadowBase,
|
||||
return true;
|
||||
}
|
||||
|
||||
PreservedAnalyses TypeSanitizerPass::run(Function &F,
|
||||
FunctionAnalysisManager &FAM) {
|
||||
TypeSanitizer TySan(*F.getParent());
|
||||
TySan.run(F, FAM.getResult<TargetLibraryAnalysis>(F));
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
|
||||
PreservedAnalyses ModuleTypeSanitizerPass::run(Module &M,
|
||||
ModuleAnalysisManager &AM) {
|
||||
PreservedAnalyses TypeSanitizerPass::run(Module &M,
|
||||
ModuleAnalysisManager &MAM) {
|
||||
Function *TysanCtorFunction;
|
||||
std::tie(TysanCtorFunction, std::ignore) =
|
||||
createSanitizerCtorAndInitFunctions(M, kTysanModuleCtorName,
|
||||
@@ -894,5 +888,12 @@ PreservedAnalyses ModuleTypeSanitizerPass::run(Module &M,
|
||||
TypeSanitizer TySan(M);
|
||||
TySan.instrumentGlobals(M);
|
||||
appendToGlobalCtors(M, TysanCtorFunction, 0);
|
||||
|
||||
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
|
||||
for (Function &F : M) {
|
||||
const TargetLibraryInfo &TLI = FAM.getResult<TargetLibraryAnalysis>(F);
|
||||
TySan.sanitizeFunction(F, TLI);
|
||||
}
|
||||
|
||||
return PreservedAnalyses::none();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
;.
|
||||
; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @tysan.module_ctor, ptr null }]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --include-generated-funcs
|
||||
; Test basic type sanitizer instrumentation.
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --include-generated-funcs
|
||||
; Test basic type sanitizer instrumentation.
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals --include-generated-funcs
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-globals --include-generated-funcs
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
!llvm.tysan.globals = !{!0}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; Test basic type sanitizer instrumentation.
|
||||
;
|
||||
; RUN: opt -passes='tysan-module,tysan' -S %s | FileCheck %s
|
||||
; RUN: opt -passes='tysan' -S %s | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user