summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/BackendUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r--clang/lib/CodeGen/BackendUtil.cpp49
1 files changed, 33 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index bf9b04f02e9f..04358cd6d7c2 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -77,6 +77,7 @@
#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
+#include "llvm/Transforms/Instrumentation/TypeSanitizer.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar/EarlyCSE.h"
#include "llvm/Transforms/Scalar/GVN.h"
@@ -735,9 +736,17 @@ 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::NumericalStability))
MPM.addPass(NumericalStabilitySanitizerPass());
+ if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+ MPM.addPass(RealtimeSanitizerPass());
+
auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) {
if (LangOpts.Sanitize.has(Mask)) {
bool UseGlobalGC = asanUseGlobalsGC(TargetTriple, CodeGenOpts);
@@ -789,13 +798,12 @@ static void addSanitizers(const Triple &TargetTriple,
}
if (LowerAllowCheckPass::IsRequested()) {
- // We can optimize after inliner, and PGO profile matching. The hook below
- // is called at the end `buildFunctionSimplificationPipeline`, which called
- // from `buildInlinerPipeline`, which called after profile matching.
- PB.registerScalarOptimizerLateEPCallback(
- [](FunctionPassManager &FPM, OptimizationLevel Level) {
- FPM.addPass(LowerAllowCheckPass());
- });
+ // We want to call it after inline, which is about OptimizerEarlyEPCallback.
+ PB.registerOptimizerEarlyEPCallback([](ModulePassManager &MPM,
+ OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase) {
+ MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass()));
+ });
}
}
@@ -1020,15 +1028,24 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
// of the pipeline.
if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
PB.registerScalarOptimizerLateEPCallback(
- [](FunctionPassManager &FPM, OptimizationLevel Level) {
- FPM.addPass(BoundsCheckingPass());
- });
-
- if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
- PB.registerScalarOptimizerLateEPCallback(
- [](FunctionPassManager &FPM, OptimizationLevel Level) {
- RealtimeSanitizerOptions Opts;
- FPM.addPass(RealtimeSanitizerPass(Opts));
+ [this](FunctionPassManager &FPM, OptimizationLevel Level) {
+ BoundsCheckingPass::ReportingMode Mode;
+ bool Merge = CodeGenOpts.SanitizeMergeHandlers.has(
+ SanitizerKind::LocalBounds);
+
+ 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;
+ }
+ BoundsCheckingPass::BoundsCheckingOptions Options(Mode, Merge);
+ FPM.addPass(BoundsCheckingPass(Options));
});
// Don't add sanitizers if we are here from ThinLTO PostLink. That already