Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -271,7 +271,7 @@ void initializeMemoryDependenceWrapperPassPass(PassRegistry&); void initializeMemorySSAPrinterLegacyPassPass(PassRegistry&); void initializeMemorySSAWrapperPassPass(PassRegistry&); -void initializeMemorySanitizerPass(PassRegistry&); +void initializeMemorySanitizerLegacyPassPass(PassRegistry&); void initializeMergeFunctionsPass(PassRegistry&); void initializeMergeICmpsPass(PassRegistry&); void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry&); Index: include/llvm/Transforms/Instrumentation.h =================================================================== --- include/llvm/Transforms/Instrumentation.h +++ include/llvm/Transforms/Instrumentation.h @@ -144,9 +144,9 @@ bool UseGlobalsGC = true); // Insert MemorySanitizer instrumentation (detection of uninitialized reads) -FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0, - bool Recover = false, - bool EnableKmsan = false); +FunctionPass *createMemorySanitizerLegacyPassPass(int TrackOrigins = 0, + bool Recover = false, + bool EnableKmsan = false); FunctionPass *createHWAddressSanitizerPass(bool CompileKernel = false, bool Recover = false); @@ -222,6 +222,24 @@ return Scaled; } +class MemorySanitizer; + +struct MemorySanitizerPass : public PassInfoMixin { + PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); + + MemorySanitizerPass(int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false); + MemorySanitizerPass(MemorySanitizerPass&&); + ~MemorySanitizerPass(); + +private: + std::unique_ptr MSanImpl; + int TrackOrigins; + bool Recover; + bool EnableKmsan; +}; + +void createMSanInitialization(Module &M); } // end namespace llvm #endif // LLVM_TRANSFORMS_INSTRUMENTATION_H Index: lib/Passes/PassRegistry.def =================================================================== --- lib/Passes/PassRegistry.def +++ lib/Passes/PassRegistry.def @@ -149,6 +149,7 @@ FUNCTION_PASS("aggressive-instcombine", AggressiveInstCombinePass()) FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass()) FUNCTION_PASS("asan", AddressSanitizerPass(false, false, false)) +FUNCTION_PASS("msan", MemorySanitizerPass()) FUNCTION_PASS("bdce", BDCEPass()) FUNCTION_PASS("bounds-checking", BoundsCheckingPass()) FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass()) Index: lib/Transforms/Instrumentation/Instrumentation.cpp =================================================================== --- lib/Transforms/Instrumentation/Instrumentation.cpp +++ lib/Transforms/Instrumentation/Instrumentation.cpp @@ -98,7 +98,7 @@ initializePGOIndirectCallPromotionLegacyPassPass(Registry); initializePGOMemOPSizeOptLegacyPassPass(Registry); initializeInstrProfilingLegacyPassPass(Registry); - initializeMemorySanitizerPass(Registry); + initializeMemorySanitizerLegacyPassPass(Registry); initializeHWAddressSanitizerPass(Registry); initializeThreadSanitizerPass(Registry); initializeSanitizerCoverageModulePass(Registry); Index: lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -424,39 +424,21 @@ &NetBSD_X86_64_MemoryMapParams, }; -namespace { +namespace llvm { /// An instrumentation pass implementing detection of uninitialized /// reads. /// /// MemorySanitizer: instrument the code in module to find /// uninitialized reads. -class MemorySanitizer : public FunctionPass { +class MemorySanitizer { public: - // Pass identification, replacement for typeid. - static char ID; - - MemorySanitizer(int TrackOrigins = 0, bool Recover = false, - bool EnableKmsan = false) - : FunctionPass(ID) { - this->CompileKernel = - ClEnableKmsan.getNumOccurrences() > 0 ? ClEnableKmsan : EnableKmsan; - if (ClTrackOrigins.getNumOccurrences() > 0) - this->TrackOrigins = ClTrackOrigins; - else - this->TrackOrigins = this->CompileKernel ? 2 : TrackOrigins; - this->Recover = ClKeepGoing.getNumOccurrences() > 0 - ? ClKeepGoing - : (this->CompileKernel | Recover); - } - StringRef getPassName() const override { return "MemorySanitizer"; } - - void getAnalysisUsage(AnalysisUsage &AU) const override { - AU.addRequired(); - } + MemorySanitizer(Module &M, int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false); - bool runOnFunction(Function &F) override; - bool doInitialization(Module &M) override; + MemorySanitizer(MemorySanitizer &&) = delete; + MemorySanitizer(const MemorySanitizer &) = delete; + bool sanitizeFunction(Function &F, const TargetLibraryInfo &TLI); private: friend struct MemorySanitizerVisitor; @@ -571,23 +553,98 @@ Function *MsanCtorFunction; }; -} // end anonymous namespace +struct MemorySanitizerLegacyPass : FunctionPass { + // Pass identification, replacement for typeid. + static char ID; + + MemorySanitizerLegacyPass(int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false) + : FunctionPass(ID), TrackOrigins(TrackOrigins), Recover(Recover), + EnableKmsan(EnableKmsan) {} + + StringRef getPassName() const override { return "MemorySanitizer"; } + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + } + + bool runOnFunction(Function &F) override; + bool doInitialization(Module &M) override; + +private: + std::unique_ptr Msan; + int TrackOrigins; + bool Recover; + bool EnableKmsan; +}; -char MemorySanitizer::ID = 0; +} // namespace llvm -INITIALIZE_PASS_BEGIN( - MemorySanitizer, "msan", - "MemorySanitizer: detects uninitialized reads.", false, false) +/// Module-level initialization. +bool MemorySanitizerLegacyPass::doInitialization(Module &M) { + createMSanInitialization(M); + Msan = make_unique(M, TrackOrigins, Recover, EnableKmsan); + return true; +} + +bool MemorySanitizerLegacyPass::runOnFunction(Function &F) { + assert(Msan); + const TargetLibraryInfo &TLI = + getAnalysis().getTLI(); + return Msan->sanitizeFunction(F, TLI); +} + +char MemorySanitizerLegacyPass::ID = 0; + +INITIALIZE_PASS_BEGIN(MemorySanitizerLegacyPass, "msan", + "MemorySanitizer: detects uninitialized reads.", false, + false) INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) -INITIALIZE_PASS_END( - MemorySanitizer, "msan", - "MemorySanitizer: detects uninitialized reads.", false, false) +INITIALIZE_PASS_END(MemorySanitizerLegacyPass, "msan", + "MemorySanitizer: detects uninitialized reads.", false, + false) + +FunctionPass *llvm::createMemorySanitizerLegacyPassPass(int TrackOrigins, + bool Recover, + bool CompileKernel) { + return new MemorySanitizerLegacyPass(TrackOrigins, Recover, CompileKernel); +} + +void llvm::createMSanInitialization(Module &M) { + if (ClEnableKmsan) + return; + Function *MsanCtorFunction = nullptr; + std::tie(MsanCtorFunction, std::ignore) = + createSanitizerCtorAndInitFunctions(M, kMsanModuleCtorName, kMsanInitName, + /*InitArgTypes=*/{}, + /*InitArgs=*/{}); + if (ClWithComdat) { + Comdat *MsanCtorComdat = M.getOrInsertComdat(kMsanModuleCtorName); + MsanCtorFunction->setComdat(MsanCtorComdat); + appendToGlobalCtors(M, MsanCtorFunction, 0, MsanCtorFunction); + } else { + appendToGlobalCtors(M, MsanCtorFunction, 0); + } +} + +PreservedAnalyses MemorySanitizerPass::run(Function &F, + FunctionAnalysisManager &FAM) { + if (!MSanImpl) + MSanImpl = make_unique(*F.getParent(), TrackOrigins, + Recover, EnableKmsan); + + MSanImpl->sanitizeFunction(F, FAM.getResult(F)); -FunctionPass *llvm::createMemorySanitizerPass(int TrackOrigins, bool Recover, - bool CompileKernel) { - return new MemorySanitizer(TrackOrigins, Recover, CompileKernel); + return PreservedAnalyses::none(); } +MemorySanitizerPass::MemorySanitizerPass(int TrackOrigins, bool Recover, + bool EnableKmsan) + : TrackOrigins(TrackOrigins), Recover(Recover), EnableKmsan(EnableKmsan) {} +MemorySanitizerPass::MemorySanitizerPass(MemorySanitizerPass&&) = default; + +MemorySanitizerPass::~MemorySanitizerPass() = default; + /// Create a non-const global initialized with the given string. /// /// Creates a writable global for Str so that we can pass it to the @@ -739,19 +796,21 @@ return; IRBuilder<> IRB(*C); - // Initialize callbacks that are common for kernel and userspace + // Initialize the ctor and callbacks that are common for kernel and userspace // instrumentation. - MsanChainOriginFn = M.getOrInsertFunction( - "__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty()); - MemmoveFn = M.getOrInsertFunction( - "__msan_memmove", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), - IRB.getInt8PtrTy(), IntptrTy); - MemcpyFn = M.getOrInsertFunction( - "__msan_memcpy", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), - IntptrTy); - MemsetFn = M.getOrInsertFunction( - "__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(), - IntptrTy); + MsanCtorFunction = cast( + M.getOrInsertFunction(kMsanModuleCtorName, IRB.getVoidTy())); + MsanChainOriginFn = M.getOrInsertFunction("__msan_chain_origin", + IRB.getInt32Ty(), IRB.getInt32Ty()); + MemmoveFn = + M.getOrInsertFunction("__msan_memmove", IRB.getInt8PtrTy(), + IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy); + MemcpyFn = + M.getOrInsertFunction("__msan_memcpy", IRB.getInt8PtrTy(), + IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IntptrTy); + MemsetFn = + M.getOrInsertFunction("__msan_memset", IRB.getInt8PtrTy(), + IRB.getInt8PtrTy(), IRB.getInt32Ty(), IntptrTy); // We insert an empty inline asm after __msan_report* to avoid callback merge. EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false), StringRef(""), StringRef(""), @@ -782,10 +841,19 @@ } } -/// Module-level initialization. -/// -/// inserts a call to __msan_init to the module's constructor list. -bool MemorySanitizer::doInitialization(Module &M) { +/// Inserts a call to __msan_init to the module's constructor list. +MemorySanitizer::MemorySanitizer(Module &M, int TrackOrigins, bool Recover, + bool EnableKmsan) { + this->CompileKernel = + ClEnableKmsan.getNumOccurrences() > 0 ? ClEnableKmsan : EnableKmsan; + if (ClTrackOrigins.getNumOccurrences() > 0) + this->TrackOrigins = ClTrackOrigins; + else + this->TrackOrigins = this->CompileKernel ? 2 : TrackOrigins; + this->Recover = ClKeepGoing.getNumOccurrences() > 0 + ? ClKeepGoing + : (this->CompileKernel | Recover); + auto &DL = M.getDataLayout(); bool ShadowPassed = ClShadowBase.getNumOccurrences() > 0; @@ -859,31 +927,18 @@ OriginStoreWeights = MDBuilder(*C).createBranchWeights(1, 1000); if (!CompileKernel) { - std::tie(MsanCtorFunction, std::ignore) = - createSanitizerCtorAndInitFunctions(M, kMsanModuleCtorName, - kMsanInitName, - /*InitArgTypes=*/{}, - /*InitArgs=*/{}); - if (ClWithComdat) { - Comdat *MsanCtorComdat = M.getOrInsertComdat(kMsanModuleCtorName); - MsanCtorFunction->setComdat(MsanCtorComdat); - appendToGlobalCtors(M, MsanCtorFunction, 0, MsanCtorFunction); - } else { - appendToGlobalCtors(M, MsanCtorFunction, 0); - } - - if (TrackOrigins) + if (this->TrackOrigins) new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, - IRB.getInt32(TrackOrigins), "__msan_track_origins"); + IRB.getInt32(this->TrackOrigins), + "__msan_track_origins"); - if (Recover) + if (this->Recover) new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, - IRB.getInt32(Recover), "__msan_keep_going"); + IRB.getInt32(this->Recover), "__msan_keep_going"); } - return true; } -namespace { +namespace llvm { /// A helper class that handles instrumentation of VarArg /// functions on a particular platform. @@ -914,7 +969,7 @@ struct MemorySanitizerVisitor; -} // end anonymous namespace +} // namespace llvm static VarArgHelper *CreateVarArgHelper(Function &Func, MemorySanitizer &Msan, MemorySanitizerVisitor &Visitor); @@ -924,7 +979,7 @@ return Log2_32_Ceil((TypeSize + 7) / 8); } -namespace { +namespace llvm { /// This class does all the work for a given function. Store and Load /// instructions store and load corresponding shadow and origin @@ -960,8 +1015,9 @@ SmallVector InstrumentationList; SmallVector StoreList; - MemorySanitizerVisitor(Function &F, MemorySanitizer &MS) - : F(F), MS(MS), VAHelper(CreateVarArgHelper(F, MS, *this)) { + MemorySanitizerVisitor(Function &F, MemorySanitizer &MS, + const TargetLibraryInfo &TLI) + : F(F), MS(MS), VAHelper(CreateVarArgHelper(F, MS, *this)), TLI(&TLI) { bool SanitizeFunction = F.hasFnAttribute(Attribute::SanitizeMemory); InsertChecks = SanitizeFunction; PropagateShadow = SanitizeFunction; @@ -970,7 +1026,6 @@ // FIXME: Consider using SpecialCaseList to specify a list of functions that // must always return fully initialized values. For now, we hardcode "main". CheckReturnValue = SanitizeFunction && (F.getName() == "main"); - TLI = &MS.getAnalysis().getTLI(); MS.initializeCallbacks(*F.getParent()); if (MS.CompileKernel) @@ -4321,7 +4376,7 @@ void finalizeInstrumentation() override {} }; -} // end anonymous namespace +} // namespace llvm static VarArgHelper *CreateVarArgHelper(Function &Func, MemorySanitizer &Msan, MemorySanitizerVisitor &Visitor) { @@ -4341,10 +4396,11 @@ return new VarArgNoOpHelper(Func, Msan, Visitor); } -bool MemorySanitizer::runOnFunction(Function &F) { +bool MemorySanitizer::sanitizeFunction(Function &F, + const TargetLibraryInfo &TLI) { if (!CompileKernel && (&F == MsanCtorFunction)) return false; - MemorySanitizerVisitor Visitor(F, *this); + MemorySanitizerVisitor Visitor(F, *this, TLI); // Clear out readonly/readnone attributes. AttrBuilder B; Index: test/Instrumentation/MemorySanitizer/AArch64/vararg.ll =================================================================== --- test/Instrumentation/MemorySanitizer/AArch64/vararg.ll +++ test/Instrumentation/MemorySanitizer/AArch64/vararg.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -msan -S | FileCheck %s +; RUN: opt < %s -passes=msan -S | FileCheck %s target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" target triple = "aarch64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll =================================================================== --- test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll +++ test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "E-m:m-i8:8:32-i16:16:32-i64:64-n32:64-S128" Index: test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll =================================================================== --- test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll +++ test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "e-m:m-i8:8:32-i16:16:32-i64:64-n32:64-S128" Index: test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll =================================================================== --- test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll +++ test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "E-m:e-i64:64-n32:64" Index: test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll =================================================================== --- test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll +++ test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "e-m:e-i64:64-n32:64" Index: test/Instrumentation/MemorySanitizer/X86/vararg-too-large.ll =================================================================== --- test/Instrumentation/MemorySanitizer/X86/vararg-too-large.ll +++ test/Instrumentation/MemorySanitizer/X86/vararg-too-large.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S 2>&1 -passes=msan | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S 2>&1 | FileCheck %s ; Test that MSan doesn't generate code overflowing __msan_va_arg_tls when too many arguments are Index: test/Instrumentation/MemorySanitizer/X86/vararg.ll =================================================================== --- test/Instrumentation/MemorySanitizer/X86/vararg.ll +++ test/Instrumentation/MemorySanitizer/X86/vararg.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan ; RUN: opt < %s -msan -msan-check-access-address=0 -S ; Test that code using va_start can be compiled on i386. Index: test/Instrumentation/MemorySanitizer/X86/vararg_call.ll =================================================================== --- test/Instrumentation/MemorySanitizer/X86/vararg_call.ll +++ test/Instrumentation/MemorySanitizer/X86/vararg_call.ll @@ -1,5 +1,10 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN" ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN" ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN ; Test that shadow and origin are stored for variadic function params. Index: test/Instrumentation/MemorySanitizer/alloca.ll =================================================================== --- test/Instrumentation/MemorySanitizer/alloca.ll +++ test/Instrumentation/MemorySanitizer/alloca.ll @@ -1,7 +1,17 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s \ +; RUN: "--check-prefixes=CHECK,INLINE" ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s --check-prefixes=CHECK,INLINE +; RUN: opt < %s -msan-check-access-address=0 -msan-poison-stack-with-call=1 -S \ +; RUN: -passes=msan | FileCheck %s "--check-prefixes=CHECK,CALL" ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-poison-stack-with-call=1 -S | FileCheck %s --check-prefixes=CHECK,CALL +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck %s "--check-prefixes=CHECK,ORIGIN" ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s --check-prefixes=CHECK,ORIGIN +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck %s "--check-prefixes=CHECK,ORIGIN" ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck %s --check-prefixes=CHECK,ORIGIN +; RUN: opt < %s -msan-kernel=1 -S -passes=msan | FileCheck %s \ +; RUN: "--check-prefixes=CHECK,KMSAN" ; RUN: opt < %s -msan -msan-kernel=1 -S | FileCheck %s --check-prefixes=CHECK,KMSAN target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/array_types.ll =================================================================== --- test/Instrumentation/MemorySanitizer/array_types.ll +++ test/Instrumentation/MemorySanitizer/array_types.ll @@ -1,4 +1,8 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS\ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/atomics.ll =================================================================== --- test/Instrumentation/MemorySanitizer/atomics.ll +++ test/Instrumentation/MemorySanitizer/atomics.ll @@ -1,5 +1,10 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/byval-alignment.ll =================================================================== --- test/Instrumentation/MemorySanitizer/byval-alignment.ll +++ test/Instrumentation/MemorySanitizer/byval-alignment.ll @@ -1,5 +1,6 @@ ; Test that copy alignment for byval arguments is limited by param-tls slot alignment. +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/check-constant-shadow.ll =================================================================== --- test/Instrumentation/MemorySanitizer/check-constant-shadow.ll +++ test/Instrumentation/MemorySanitizer/check-constant-shadow.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -msan-check-constant-shadow=1 \ +; RUN: -msan-track-origins=1 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-check-constant-shadow=1 -msan-track-origins=1 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/check_access_address.ll =================================================================== --- test/Instrumentation/MemorySanitizer/check_access_address.ll +++ test/Instrumentation/MemorySanitizer/check_access_address.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=1 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=1 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/csr.ll =================================================================== --- test/Instrumentation/MemorySanitizer/csr.ll +++ test/Instrumentation/MemorySanitizer/csr.ll @@ -1,4 +1,7 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=1 -S -passes=msan | FileCheck %s \ +; RUN: --check-prefix=ADDR ; RUN: opt < %s -msan -msan-check-access-address=1 -S | FileCheck %s --check-prefix=ADDR ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll =================================================================== --- test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll +++ test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll @@ -1,4 +1,6 @@ ; MSan converts 2-element global_ctors to 3-element when adding the new entry. +; RUN: opt < %s -msan-with-comdat -S -passes=msan -add-sanitizer-init=msan \ +; RUN: | FileCheck %s ; RUN: opt < %s -msan -msan-with-comdat -S | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/instrumentation-with-call-threshold.ll =================================================================== --- test/Instrumentation/MemorySanitizer/instrumentation-with-call-threshold.ll +++ test/Instrumentation/MemorySanitizer/instrumentation-with-call-threshold.ll @@ -2,8 +2,19 @@ ; Test that in with-calls mode there are no calls to __msan_chain_origin - they ; are done from __msan_maybe_store_origin_*. +; RUN: opt < %s -msan-check-access-address=0 \ +; RUN: -msan-instrumentation-with-call-threshold=0 -S -passes=msan | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-instrumentation-with-call-threshold=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 \ +; RUN: -msan-instrumentation-with-call-threshold=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS\ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-instrumentation-with-call-threshold=0 -msan-track-origins=1 -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s +; RUN: opt < %s -msan-check-access-address=0 \ +; RUN: -msan-instrumentation-with-call-threshold=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS\ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-instrumentation-with-call-threshold=0 -msan-track-origins=2 -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/manual-shadow.ll =================================================================== --- test/Instrumentation/MemorySanitizer/manual-shadow.ll +++ test/Instrumentation/MemorySanitizer/manual-shadow.ll @@ -1,9 +1,20 @@ ; Test that the msan layout customization options work as expected ; +; RUN: opt < %s -msan-shadow-base 3735928559 -S -passes=msan | FileCheck \ +; RUN: --check-prefix=CHECK-BASE %s ; RUN: opt < %s -msan -msan-shadow-base 3735928559 -S | FileCheck --check-prefix=CHECK-BASE %s +; RUN: opt < %s -msan-shadow-base 3735928559 -msan-and-mask 4294901760 -S \ +; RUN: -passes=msan | FileCheck --check-prefix=CHECK-AND %s ; RUN: opt < %s -msan -msan-shadow-base 3735928559 -msan-and-mask 4294901760 -S | FileCheck --check-prefix=CHECK-AND %s +; RUN: opt < %s -msan-shadow-base 3735928559 -msan-xor-mask 48879 -S \ +; RUN: -passes=msan | FileCheck --check-prefix=CHECK-XOR %s ; RUN: opt < %s -msan -msan-shadow-base 3735928559 -msan-xor-mask 48879 -S | FileCheck --check-prefix=CHECK-XOR %s +; RUN: opt < %s -msan-shadow-base 3735928559 -msan-xor-mask 48879 \ +; RUN: -msan-and-mask 4294901760 -S -passes=msan | FileCheck \ +; RUN: --check-prefix=CHECK-XOR-AND %s ; RUN: opt < %s -msan -msan-shadow-base 3735928559 -msan-xor-mask 48879 -msan-and-mask 4294901760 -S | FileCheck --check-prefix=CHECK-XOR-AND %s +; RUN: opt < %s -msan-track-origins 1 -msan-origin-base 1777777 -S -passes=msan\ +; RUN: | FileCheck --check-prefix=CHECK-ORIGIN-BASE %s ; RUN: opt < %s -msan -msan-track-origins 1 -msan-origin-base 1777777 -S | FileCheck --check-prefix=CHECK-ORIGIN-BASE %s target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/masked-store-load.ll =================================================================== --- test/Instrumentation/MemorySanitizer/masked-store-load.ll +++ test/Instrumentation/MemorySanitizer/masked-store-load.ll @@ -1,5 +1,10 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck %s "--check-prefixes=CHECK,CHECK-ORIGIN" ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s --check-prefixes=CHECK,CHECK-ORIGIN +; RUN: opt < %s -msan-check-access-address=1 -S -passes=msan | FileCheck %s \ +; RUN: --check-prefix=ADDR ; RUN: opt < %s -msan -msan-check-access-address=1 -S | FileCheck %s --check-prefix=ADDR target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/missing_origin.ll =================================================================== --- test/Instrumentation/MemorySanitizer/missing_origin.ll +++ test/Instrumentation/MemorySanitizer/missing_origin.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/msan_basic.ll =================================================================== --- test/Instrumentation/MemorySanitizer/msan_basic.ll +++ test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -1,5 +1,15 @@ -; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck -allow-deprecated-dag-overlap %s -; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -allow-deprecated-dag-overlap -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan \ +; RUN: -add-sanitizer-init=msan \ +; RUN: | FileCheck -allow-deprecated-dag-overlap %s +; RUN: opt < %s -msan -msan-check-access-address=0 -S \ +; RUN: | FileCheck -allow-deprecated-dag-overlap %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan -add-sanitizer-init=msan \ +; RUN: | FileCheck -allow-deprecated-dag-overlap \ +; RUN: -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s +; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: | FileCheck -allow-deprecated-dag-overlap -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll =================================================================== --- test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll +++ test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll @@ -1,4 +1,6 @@ ; KMSAN instrumentation tests +; RUN: opt < %s -msan-kernel=1 -S -passes=msan | FileCheck %s \ +; RUN: -check-prefixes=CHECK ; RUN: opt < %s -msan -msan-kernel=1 -S | FileCheck %s -check-prefixes=CHECK target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/msan_x86_bts_asm.ll =================================================================== --- test/Instrumentation/MemorySanitizer/msan_x86_bts_asm.ll +++ test/Instrumentation/MemorySanitizer/msan_x86_bts_asm.ll @@ -1,5 +1,9 @@ ; Test for the conservative assembly handling mode used by KMSAN. +; RUN: opt < %s -msan-check-access-address=0 -msan-handle-asm-conservative=0 -S\ +; RUN: -passes=msan | FileCheck "-check-prefixes=CHECK,CHECK-NONCONS" %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-handle-asm-conservative=0 -S | FileCheck -check-prefixes=CHECK,CHECK-NONCONS %s +; RUN: opt < %s -msan-check-access-address=0 -msan-handle-asm-conservative=1 -S\ +; RUN: -passes=msan | FileCheck "-check-prefixes=CHECK,CHECK-CONS" %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-handle-asm-conservative=1 -S | FileCheck -check-prefixes=CHECK,CHECK-CONS %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/msan_x86intrinsics.ll =================================================================== --- test/Instrumentation/MemorySanitizer/msan_x86intrinsics.ll +++ test/Instrumentation/MemorySanitizer/msan_x86intrinsics.ll @@ -1,4 +1,8 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS\ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS %s ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/mul_by_constant.ll =================================================================== --- test/Instrumentation/MemorySanitizer/mul_by_constant.ll +++ test/Instrumentation/MemorySanitizer/mul_by_constant.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/nosanitize.ll =================================================================== --- test/Instrumentation/MemorySanitizer/nosanitize.ll +++ test/Instrumentation/MemorySanitizer/nosanitize.ll @@ -1,5 +1,7 @@ ; Verify that calls with !nosanitize are not instrumented by MSan. +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s +; RUN: opt < %s -msan-track-origins=1 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-track-origins=1 -S | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/origin-alignment.ll =================================================================== --- test/Instrumentation/MemorySanitizer/origin-alignment.ll +++ test/Instrumentation/MemorySanitizer/origin-alignment.ll @@ -1,4 +1,10 @@ +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS1 %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS1 %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS2 %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck -check-prefix=CHECK -check-prefix=CHECK-ORIGINS2 %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/origin-array.ll =================================================================== --- test/Instrumentation/MemorySanitizer/origin-array.ll +++ test/Instrumentation/MemorySanitizer/origin-array.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck %s target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" Index: test/Instrumentation/MemorySanitizer/pr32842.ll =================================================================== --- test/Instrumentation/MemorySanitizer/pr32842.ll +++ test/Instrumentation/MemorySanitizer/pr32842.ll @@ -1,5 +1,6 @@ ; Regression test for https://bugs.llvm.org/show_bug.cgi?id=32842 ; +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s ;target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/return_from_main.ll =================================================================== --- test/Instrumentation/MemorySanitizer/return_from_main.ll +++ test/Instrumentation/MemorySanitizer/return_from_main.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/store-long-origin.ll =================================================================== --- test/Instrumentation/MemorySanitizer/store-long-origin.ll +++ test/Instrumentation/MemorySanitizer/store-long-origin.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/store-origin.ll =================================================================== --- test/Instrumentation/MemorySanitizer/store-origin.ll +++ test/Instrumentation/MemorySanitizer/store-origin.ll @@ -1,5 +1,13 @@ +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes=msan | FileCheck \ +; RUN: "-check-prefixes=CHECK,CHECK-MSAN,CHECK-ORIGINS1" %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=1 -S | FileCheck -check-prefixes=CHECK,CHECK-MSAN,CHECK-ORIGINS1 %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=2 -S \ +; RUN: -passes=msan | FileCheck \ +; RUN: "-check-prefixes=CHECK,CHECK-MSAN,CHECK-ORIGINS2" %s ; RUN: opt < %s -msan -msan-check-access-address=0 -msan-track-origins=2 -S | FileCheck -check-prefixes=CHECK,CHECK-MSAN,CHECK-ORIGINS2 %s +; RUN: opt < %s -msan-kernel=1 -msan-check-access-address=0 -S -passes=msan | \ +; RUN: FileCheck "-check-prefixes=CHECK,CHECK-KMSAN,CHECK-ORIGINS2" %s ; RUN: opt < %s -msan -msan-kernel=1 -msan-check-access-address=0 -S | FileCheck -check-prefixes=CHECK,CHECK-KMSAN,CHECK-ORIGINS2 %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/str-nobuiltin.ll =================================================================== --- test/Instrumentation/MemorySanitizer/str-nobuiltin.ll +++ test/Instrumentation/MemorySanitizer/str-nobuiltin.ll @@ -1,5 +1,6 @@ ; Test marking string functions as nobuiltin in memory sanitizer. ; +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/unreachable.ll =================================================================== --- test/Instrumentation/MemorySanitizer/unreachable.ll +++ test/Instrumentation/MemorySanitizer/unreachable.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" Index: test/Instrumentation/MemorySanitizer/unsized_type.ll =================================================================== --- test/Instrumentation/MemorySanitizer/unsized_type.ll +++ test/Instrumentation/MemorySanitizer/unsized_type.ll @@ -1,5 +1,6 @@ ; Check that unsized token types used by coroutine intrinsics do not cause ; assertion failures. +; RUN: opt < %s -S 2>&1 -passes=msan | FileCheck %s ; RUN: opt < %s -msan -S 2>&1 | FileCheck %s target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" Index: test/Instrumentation/MemorySanitizer/vector_arith.ll =================================================================== --- test/Instrumentation/MemorySanitizer/vector_arith.ll +++ test/Instrumentation/MemorySanitizer/vector_arith.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/vector_cmp.ll =================================================================== --- test/Instrumentation/MemorySanitizer/vector_cmp.ll +++ test/Instrumentation/MemorySanitizer/vector_cmp.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/vector_cvt.ll =================================================================== --- test/Instrumentation/MemorySanitizer/vector_cvt.ll +++ test/Instrumentation/MemorySanitizer/vector_cvt.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/vector_pack.ll =================================================================== --- test/Instrumentation/MemorySanitizer/vector_pack.ll +++ test/Instrumentation/MemorySanitizer/vector_pack.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/vector_shift.ll =================================================================== --- test/Instrumentation/MemorySanitizer/vector_shift.ll +++ test/Instrumentation/MemorySanitizer/vector_shift.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes=msan | FileCheck %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: test/Instrumentation/MemorySanitizer/with-call-type-size.ll =================================================================== --- test/Instrumentation/MemorySanitizer/with-call-type-size.ll +++ test/Instrumentation/MemorySanitizer/with-call-type-size.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-instrumentation-with-call-threshold=0 -S -passes=msan | \ +; RUN: FileCheck %s ; RUN: opt < %s -msan -msan-instrumentation-with-call-threshold=0 -S | FileCheck %s target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" @@ -82,4 +84,4 @@ ; CHECK-NOT: call void @__msan_maybe_warning_ ; CHECK: icmp ne i65 %{{.*}}, 0 ; CHECK-NOT: call void @__msan_maybe_warning_ -; CHECK: ret <4 x i32> \ No newline at end of file +; CHECK: ret <4 x i32> Index: tools/opt/NewPMDriver.cpp =================================================================== --- tools/opt/NewPMDriver.cpp +++ tools/opt/NewPMDriver.cpp @@ -57,6 +57,15 @@ "pipeline for handling managed aliasing queries"), cl::Hidden); +namespace { +enum class SanitizerInit { msan }; +} + +static cl::list SanitizerInitialization( + "add-sanitizer-init", cl::CommaSeparated, + cl::desc("Add sanitizer initialization to the global ctor"), + cl::values(clEnumValN(SanitizerInit::msan, "msan", "Memory Sanitizer"))); + /// {{@ These options accept textual pipeline descriptions which will be /// inserted into default pipelines at the respective extension points static cl::opt PeepholeEPPipeline( @@ -190,6 +199,16 @@ } #endif +static void addSanitizerInitializations(Module &M) { + for (auto &San : SanitizerInitialization) { + switch (San) { + case SanitizerInit::msan: + createMSanInitialization(M); + break; + } + } +} + bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM, ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut, ToolOutputFile *OptRemarkFile, @@ -315,6 +334,10 @@ // Before executing passes, print the final values of the LLVM options. cl::PrintOptionValues(); + // Add the sanitizer initializers first, so that sanitizer passes can find + // them + addSanitizerInitializations(M); + // Now that we have all of the passes ready, run them. MPM.run(M, MAM);