diff options
author | Vitaly Buka <vitalybuka@google.com> | 2024-12-19 16:38:07 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-19 16:38:07 -0800 |
commit | c2aee5062087f193cb5756f378c248c7d91b7245 (patch) | |
tree | 7bed90f000597ae31b191e815becc6f0875de284 /clang/lib/CodeGen/BackendUtil.cpp | |
parent | 44201679c6ec597a8624b38ff8f056c5a8dab901 (diff) | |
download | llvm-c2aee5062087f193cb5756f378c248c7d91b7245.zip llvm-c2aee5062087f193cb5756f378c248c7d91b7245.tar.gz llvm-c2aee5062087f193cb5756f378c248c7d91b7245.tar.bz2 |
[ubsan] Runtime and driver support for local-bounds (#120515)
Implements ``-f[no-]sanitize-trap=local-bounds``,
and ``-f[no-]sanitize-recover=local-bounds``.
LLVM part is here #120513.
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index b1003f2..e6c9d77 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1028,9 +1028,20 @@ void EmitAssemblyHelper::RunOptimizationPipeline( // of the pipeline. if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback( - [](FunctionPassManager &FPM, OptimizationLevel Level) { - FPM.addPass( - BoundsCheckingPass(BoundsCheckingPass::ReportingMode::Trap)); + [this](FunctionPassManager &FPM, OptimizationLevel Level) { + BoundsCheckingPass::ReportingMode Mode; + if (CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) { + Mode = BoundsCheckingPass::ReportingMode::Trap; + } else if (CodeGenOpts.SanitizeMinimalRuntime) { + Mode = CodeGenOpts.SanitizeRecover.has(SanitizerKind::LocalBounds) + ? BoundsCheckingPass::ReportingMode::MinRuntime + : BoundsCheckingPass::ReportingMode::MinRuntimeAbort; + } else { + Mode = CodeGenOpts.SanitizeRecover.has(SanitizerKind::LocalBounds) + ? BoundsCheckingPass::ReportingMode::FullRuntime + : BoundsCheckingPass::ReportingMode::FullRuntimeAbort; + } + FPM.addPass(BoundsCheckingPass(Mode)); }); // Don't add sanitizers if we are here from ThinLTO PostLink. That already |