diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2017-11-14 01:59:18 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2017-11-14 01:59:18 +0000 |
commit | a8bd4e3816a0c54411cc97d264de72ccc5333098 (patch) | |
tree | 21aee5ed7ac97e0034a3fed149a75d9ecade856a /clang/lib/CodeGen/BackendUtil.cpp | |
parent | afce44949a795e5218068dcf0f79526ea3cc3f66 (diff) | |
download | bcm5719-llvm-a8bd4e3816a0c54411cc97d264de72ccc5333098.tar.gz bcm5719-llvm-a8bd4e3816a0c54411cc97d264de72ccc5333098.zip |
[PM] Wire up support for the bounds checking sanitizer with the new PM.
Not much interesting here. Mostly wiring things together.
One thing worth noting is that the approach is substantially different
from the old PM. Here, the -O0 case works fundamentally differently in
that we just directly build the pipeline without any callbacks or other
cruft. In some ways, this is nice and clean. However, I don't like that
it causes the sanitizers to be enabled with different changes at
different times. =/ Suggestions for a better way to do this are welcome.
Differential Revision: https://reviews.llvm.org/D39085
llvm-svn: 318131
Diffstat (limited to 'clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r-- | clang/lib/CodeGen/BackendUtil.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 35b83b7cece..9496f5205e9 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -900,6 +900,12 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( // Build a minimal pipeline based on the semantics required by Clang, // which is just that always inlining occurs. MPM.addPass(AlwaysInlinerPass()); + + // At -O0 we directly run necessary sanitizer passes. + if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) + MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass())); + + // Lastly, add a semantically necessary pass for ThinLTO. if (IsThinLTO) MPM.addPass(NameAnonGlobalPass()); } else { @@ -907,6 +913,14 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager( // configure the pipeline. PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts); + // Register callbacks to schedule sanitizer passes at the appropriate part of + // the pipeline. + if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) + PB.registerScalarOptimizerLateEPCallback( + [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { + FPM.addPass(BoundsCheckingPass()); + }); + if (IsThinLTO) { MPM = PB.buildThinLTOPreLinkDefaultPipeline( Level, CodeGenOpts.DebugPassManager); |