From: Petr Hosek Date: Thu, 9 May 2019 06:09:35 +0000 (+0000) Subject: [NewPM] Setup Passes for KASan and KMSan X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ba126ade702c14d2e52a1cceda4ca66c8fb47ad;p=clang [NewPM] Setup Passes for KASan and KMSan While ASan and MSan passes were already ported to new PM, the kernel variants weren't setup in the pipeline which makes the KASan and KMSan tests in Clang fail. Differential Revision: https://reviews.llvm.org/D61664 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360313 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/BackendUtil.cpp b/lib/CodeGen/BackendUtil.cpp index cd2a5f6fa3..f6018e7d62 100644 --- a/lib/CodeGen/BackendUtil.cpp +++ b/lib/CodeGen/BackendUtil.cpp @@ -931,22 +931,34 @@ static void addSanitizersAtO0(ModulePassManager &MPM, const Triple &TargetTriple, const LangOptions &LangOpts, const CodeGenOptions &CodeGenOpts) { - if (LangOpts.Sanitize.has(SanitizerKind::Address)) { + auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) { MPM.addPass(RequireAnalysisPass()); - bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Address); - MPM.addPass(createModuleToFunctionPassAdaptor( - AddressSanitizerPass(/*CompileKernel=*/false, Recover, - CodeGenOpts.SanitizeAddressUseAfterScope))); + bool Recover = CodeGenOpts.SanitizeRecover.has(Mask); + MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass( + CompileKernel, Recover, CodeGenOpts.SanitizeAddressUseAfterScope))); bool ModuleUseAfterScope = asanUseGlobalsGC(TargetTriple, CodeGenOpts); - MPM.addPass(ModuleAddressSanitizerPass( - /*CompileKernel=*/false, Recover, ModuleUseAfterScope, - CodeGenOpts.SanitizeAddressUseOdrIndicator)); + MPM.addPass( + ModuleAddressSanitizerPass(CompileKernel, Recover, ModuleUseAfterScope, + CodeGenOpts.SanitizeAddressUseOdrIndicator)); + }; + + if (LangOpts.Sanitize.has(SanitizerKind::Address)) { + ASanPass(SanitizerKind::Address, /*CompileKernel=*/false); + } + + if (LangOpts.Sanitize.has(SanitizerKind::KernelAddress)) { + ASanPass(SanitizerKind::KernelAddress, /*CompileKernel=*/true); } if (LangOpts.Sanitize.has(SanitizerKind::Memory)) { MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({}))); } + if (LangOpts.Sanitize.has(SanitizerKind::KernelMemory)) { + MPM.addPass(createModuleToFunctionPassAdaptor( + MemorySanitizerPass({0, false, /*Kernel=*/true}))); + } + if (LangOpts.Sanitize.has(SanitizerKind::Thread)) { MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); }