[clang] [llvm] [tysan] Convert TySan from function+module pass to just module pass (PR #120667)
Enna1 wrote: @vitalybuka any comments ? :) https://github.com/llvm/llvm-project/pull/120667 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [tysan] Convert TySan from function+module pass to just module pass (PR #120667)
https://github.com/Enna1 updated https://github.com/llvm/llvm-project/pull/120667 >From 7cef5a275b176b8cf8703ae3b372637a1dded326 Mon Sep 17 00:00:00 2001 From: "xumingjie.enna1" Date: Thu, 19 Dec 2024 20:38:09 +0800 Subject: [PATCH 1/2] [tysan] Convert TySan from function+module pass to just module pass As mentioned in https://github.com/llvm/llvm-project/pull/118989, all sanitizers but tsan are converted to just module pass for easier maintainence. This patch removes the TySan function pass, convert TySan from function+module pass to just module pass. --- clang/lib/CodeGen/BackendUtil.cpp | 6 ++--- .../Instrumentation/TypeSanitizer.h | 10 + llvm/lib/Passes/PassRegistry.def | 3 +-- .../Instrumentation/TypeSanitizer.cpp | 22 +-- .../TypeSanitizer/access-with-offset.ll | 2 +- .../TypeSanitizer/alloca-only.ll | 2 +- .../Instrumentation/TypeSanitizer/alloca.ll | 2 +- .../Instrumentation/TypeSanitizer/anon.ll | 2 +- .../TypeSanitizer/basic-nosan.ll | 2 +- .../Instrumentation/TypeSanitizer/basic.ll| 2 +- .../Instrumentation/TypeSanitizer/byval.ll| 2 +- .../Instrumentation/TypeSanitizer/globals.ll | 2 +- .../TypeSanitizer/invalid-metadata.ll | 2 +- .../TypeSanitizer/memintrinsics.ll| 2 +- .../TypeSanitizer/nosanitize.ll | 2 +- .../TypeSanitizer/sanitize-no-tbaa.ll | 2 +- .../TypeSanitizer/swifterror.ll | 2 +- 17 files changed, 28 insertions(+), 39 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b1003f2ce5032e..bab3520758fa4b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -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()); diff --git a/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h index a6cc56df35f14d..20f08b67908556 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h @@ -20,19 +20,11 @@ class Function; class FunctionPass; class Module; -/// A function pass for tysan instrumentation. struct TypeSanitizerPass : public PassInfoMixin { - 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 { PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); static bool isRequired() { return true; } }; } // namespace llvm + #endif /* LLVM_TRANSFORMS_INSTRUMENTATION_TYPESANITIZER_H */ diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index ecc9f554937103..98542c78ddf31b 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -157,7 +157,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()) @@ -482,7 +482,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()) diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp index 19610958e47b72..f22d83d51aff65 100644 --- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp @@ -70,7 +70,7 @@ namespace { /// violations. struct TypeSanitizer { TypeSanitizer(Module &M); - bool run(Function &F, const TargetLibraryInfo &TLI); + bool sani
[clang] [llvm] [tysan] Convert TySan from function+module pass to just module pass (PR #120667)
https://github.com/Enna1 created https://github.com/llvm/llvm-project/pull/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. >From 7cef5a275b176b8cf8703ae3b372637a1dded326 Mon Sep 17 00:00:00 2001 From: "xumingjie.enna1" Date: Thu, 19 Dec 2024 20:38:09 +0800 Subject: [PATCH] [tysan] Convert TySan from function+module pass to just module pass As mentioned in https://github.com/llvm/llvm-project/pull/118989, all sanitizers but tsan are converted to just module pass for easier maintainence. This patch removes the TySan function pass, convert TySan from function+module pass to just module pass. --- clang/lib/CodeGen/BackendUtil.cpp | 6 ++--- .../Instrumentation/TypeSanitizer.h | 10 + llvm/lib/Passes/PassRegistry.def | 3 +-- .../Instrumentation/TypeSanitizer.cpp | 22 +-- .../TypeSanitizer/access-with-offset.ll | 2 +- .../TypeSanitizer/alloca-only.ll | 2 +- .../Instrumentation/TypeSanitizer/alloca.ll | 2 +- .../Instrumentation/TypeSanitizer/anon.ll | 2 +- .../TypeSanitizer/basic-nosan.ll | 2 +- .../Instrumentation/TypeSanitizer/basic.ll| 2 +- .../Instrumentation/TypeSanitizer/byval.ll| 2 +- .../Instrumentation/TypeSanitizer/globals.ll | 2 +- .../TypeSanitizer/invalid-metadata.ll | 2 +- .../TypeSanitizer/memintrinsics.ll| 2 +- .../TypeSanitizer/nosanitize.ll | 2 +- .../TypeSanitizer/sanitize-no-tbaa.ll | 2 +- .../TypeSanitizer/swifterror.ll | 2 +- 17 files changed, 28 insertions(+), 39 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b1003f2ce5032e..bab3520758fa4b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -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()); diff --git a/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h index a6cc56df35f14d..20f08b67908556 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h @@ -20,19 +20,11 @@ class Function; class FunctionPass; class Module; -/// A function pass for tysan instrumentation. struct TypeSanitizerPass : public PassInfoMixin { - 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 { PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); static bool isRequired() { return true; } }; } // namespace llvm + #endif /* LLVM_TRANSFORMS_INSTRUMENTATION_TYPESANITIZER_H */ diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index ecc9f554937103..98542c78ddf31b 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -157,7 +157,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()) @@ -482,7 +482,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()) diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp index 19610958e47b72..f22d83d51aff65 100644 --- a/llvm/lib/Transforms/Instrumen
[clang] [compiler-rt] [llvm] [TySan] A Type Sanitizer (Runtime Library) (PR #76261)
Enna1 wrote: > @fhahn can TySan be made to trap when it detects a problem? I tried > `-fsanitize-trap=type` but got: > > `clang++: error: unsupported argument 'type' to option '-fsanitize-trap='` > > `-fsanitize-trap=all` does not seem to result in TySan trapping, only > logging... `-fsanitize-trap` only supports UBSan and CFI, see https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/SanitizerArgs.cpp#L66. If we want TySan to stop and abort when it detects first type-based aliasing violation, I would suggest implement `halt_on_error` support for TySan and default `halt_on_error` to false. For reference, TSan defaults `halt_on_error` to false, see https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/tsan/rtl/tsan_flags.inc#L45. https://github.com/llvm/llvm-project/pull/76261 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [tysan] Convert TySan from function+module pass to just module pass (PR #120667)
https://github.com/Enna1 updated https://github.com/llvm/llvm-project/pull/120667 >From 7cef5a275b176b8cf8703ae3b372637a1dded326 Mon Sep 17 00:00:00 2001 From: "xumingjie.enna1" Date: Thu, 19 Dec 2024 20:38:09 +0800 Subject: [PATCH 1/2] [tysan] Convert TySan from function+module pass to just module pass As mentioned in https://github.com/llvm/llvm-project/pull/118989, all sanitizers but tsan are converted to just module pass for easier maintainence. This patch removes the TySan function pass, convert TySan from function+module pass to just module pass. --- clang/lib/CodeGen/BackendUtil.cpp | 6 ++--- .../Instrumentation/TypeSanitizer.h | 10 + llvm/lib/Passes/PassRegistry.def | 3 +-- .../Instrumentation/TypeSanitizer.cpp | 22 +-- .../TypeSanitizer/access-with-offset.ll | 2 +- .../TypeSanitizer/alloca-only.ll | 2 +- .../Instrumentation/TypeSanitizer/alloca.ll | 2 +- .../Instrumentation/TypeSanitizer/anon.ll | 2 +- .../TypeSanitizer/basic-nosan.ll | 2 +- .../Instrumentation/TypeSanitizer/basic.ll| 2 +- .../Instrumentation/TypeSanitizer/byval.ll| 2 +- .../Instrumentation/TypeSanitizer/globals.ll | 2 +- .../TypeSanitizer/invalid-metadata.ll | 2 +- .../TypeSanitizer/memintrinsics.ll| 2 +- .../TypeSanitizer/nosanitize.ll | 2 +- .../TypeSanitizer/sanitize-no-tbaa.ll | 2 +- .../TypeSanitizer/swifterror.ll | 2 +- 17 files changed, 28 insertions(+), 39 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b1003f2ce5032e..bab3520758fa4b 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -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()); diff --git a/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h index a6cc56df35f14d..20f08b67908556 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/TypeSanitizer.h @@ -20,19 +20,11 @@ class Function; class FunctionPass; class Module; -/// A function pass for tysan instrumentation. struct TypeSanitizerPass : public PassInfoMixin { - 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 { PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); static bool isRequired() { return true; } }; } // namespace llvm + #endif /* LLVM_TRANSFORMS_INSTRUMENTATION_TYPESANITIZER_H */ diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index ecc9f554937103..98542c78ddf31b 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -157,7 +157,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()) @@ -482,7 +482,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()) diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp index 19610958e47b72..f22d83d51aff65 100644 --- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp @@ -70,7 +70,7 @@ namespace { /// violations. struct TypeSanitizer { TypeSanitizer(Module &M); - bool run(Function &F, const TargetLibraryInfo &TLI); + bool sani