diff options
author | Thurston Dang <thurston@google.com> | 2025-01-29 21:03:26 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-29 21:03:26 -0800 |
commit | dccd27112722109d2e2f03e8da9ce8690f06e11b (patch) | |
tree | d8ef8182f3d734069d6a26c3047a531dfaabcf0c /clang/lib/CodeGen/BackendUtil.cpp | |
parent | 4b2d6157744ca7693e6e904bd53d435df1ff6ee8 (diff) | |
download | llvm-dccd27112722109d2e2f03e8da9ce8690f06e11b.zip llvm-dccd27112722109d2e2f03e8da9ce8690f06e11b.tar.gz llvm-dccd27112722109d2e2f03e8da9ce8690f06e11b.tar.bz2 |
[ubsan] Connect -fsanitize-skip-hot-cutoff to LowerAllowCheckPass<cutoffs> (#124857)
This adds the plumbing between -fsanitize-skip-hot-cutoff (introduced in
https://github.com/llvm/llvm-project/pull/121619) and
LowerAllowCheckPass<cutoffs> (introduced in
https://github.com/llvm/llvm-project/pull/124211).
The net effect is that -fsanitize-skip-hot-cutoff now combines the
functionality of -ubsan-guard-checks and
-lower-allow-check-percentile-cutoff (though this patch does not remove
those yet), and generalizes the latter to allow per-sanitizer cutoffs.
Note: this patch replaces Intrinsic::allow_ubsan_check's
SanitizerHandler parameter with SanitizerOrdinal; this is necessary
because the hot cutoffs are specified in terms of SanitizerOrdinal
(e.g., null, alignment), not SanitizerHandler (e.g., TypeMismatch).
Likewise, CodeGenFunction::EmitCheck is changed to emit
allow_ubsan_check() for each individual check.
---------
Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
Co-authored-by: Vitaly Buka <vitalybuka@google.com>
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 3e65eeb..bc32878 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -795,12 +795,20 @@ static void addSanitizers(const Triple &TargetTriple, PB.registerOptimizerLastEPCallback(SanitizersCallback); } - if (LowerAllowCheckPass::IsRequested()) { + // SanitizeSkipHotCutoffs: doubles with range [0, 1] + // Opts.cutoffs: unsigned ints with range [0, 1000000] + auto ScaledCutoffs = CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000); + + // TODO: remove IsRequested() + if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value()) { // We want to call it after inline, which is about OptimizerEarlyEPCallback. PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM, OptimizationLevel Level, ThinOrFullLTOPhase Phase) { LowerAllowCheckPass::Options Opts; + // TODO: after removing IsRequested(), make this unconditional + if (ScaledCutoffs.has_value()) + Opts.cutoffs = ScaledCutoffs.value(); MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts))); }); } |