Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -276,7 +276,7 @@ const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts(); int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins; bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::Memory); - PM.add(createMemorySanitizerPass(TrackOrigins, Recover, CompileKernel)); + PM.add(createMemorySanitizerLegacyPassPass(TrackOrigins, Recover, CompileKernel)); // MemorySanitizer inserts complex instrumentation that mostly follows // the logic of the original code, but operates on "shadow" values. Index: llvm/bindings/go/llvm/InstrumentationBindings.h =================================================================== --- llvm/bindings/go/llvm/InstrumentationBindings.h +++ llvm/bindings/go/llvm/InstrumentationBindings.h @@ -27,7 +27,7 @@ void LLVMAddAddressSanitizerFunctionPass(LLVMPassManagerRef PM); void LLVMAddAddressSanitizerModulePass(LLVMPassManagerRef PM); void LLVMAddThreadSanitizerPass(LLVMPassManagerRef PM); -void LLVMAddMemorySanitizerPass(LLVMPassManagerRef PM); +void LLVMAddMemorySanitizerLegacyPassPass(LLVMPassManagerRef PM); void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM, int ABIListFilesNum, const char **ABIListFiles); Index: llvm/bindings/go/llvm/InstrumentationBindings.cpp =================================================================== --- llvm/bindings/go/llvm/InstrumentationBindings.cpp +++ llvm/bindings/go/llvm/InstrumentationBindings.cpp @@ -31,8 +31,8 @@ unwrap(PM)->add(createThreadSanitizerPass()); } -void LLVMAddMemorySanitizerPass(LLVMPassManagerRef PM) { - unwrap(PM)->add(createMemorySanitizerPass()); +void LLVMAddMemorySanitizerLegacyPassPass(LLVMPassManagerRef PM) { + unwrap(PM)->add(createMemorySanitizerLegacyPassPass()); } void LLVMAddDataFlowSanitizerPass(LLVMPassManagerRef PM, Index: llvm/bindings/go/llvm/transforms_instrumentation.go =================================================================== --- llvm/bindings/go/llvm/transforms_instrumentation.go +++ llvm/bindings/go/llvm/transforms_instrumentation.go @@ -32,8 +32,8 @@ C.LLVMAddThreadSanitizerPass(pm.C) } -func (pm PassManager) AddMemorySanitizerPass() { - C.LLVMAddMemorySanitizerPass(pm.C) +func (pm PassManager) AddMemorySanitizerLegacyPassPass() { + C.LLVMAddMemorySanitizerLegacyPassPass(pm.C) } func (pm PassManager) AddDataFlowSanitizerPass(abilist []string) { Index: llvm/include/llvm/InitializePasses.h =================================================================== --- llvm/include/llvm/InitializePasses.h +++ llvm/include/llvm/InitializePasses.h @@ -273,7 +273,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: llvm/include/llvm/Transforms/Instrumentation.h =================================================================== --- llvm/include/llvm/Transforms/Instrumentation.h +++ llvm/include/llvm/Transforms/Instrumentation.h @@ -16,6 +16,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/PassManager.h" #include #include #include @@ -153,7 +154,7 @@ bool UseOdrIndicator = true); // Insert MemorySanitizer instrumentation (detection of uninitialized reads) -FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0, +FunctionPass *createMemorySanitizerLegacyPassPass(int TrackOrigins = 0, bool Recover = false, bool EnableKmsan = false); @@ -231,6 +232,35 @@ return Scaled; } +struct MemorySanitizerOptions { + MemorySanitizerOptions(int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false); + + /// Track origins (allocation points) of uninitialized values. + int TrackOrigins; + bool Recover; + /// True if we're compiling the Linux kernel. + bool CompileKernel; +}; + +struct MemorySanitizerInitPass : public PassInfoMixin { + MemorySanitizerInitPass(int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false) + : MSanOptions(TrackOrigins, Recover, EnableKmsan) {} + + PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); + MemorySanitizerOptions MSanOptions; +}; + +struct MemorySanitizerPass : public PassInfoMixin { + MemorySanitizerPass(int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false) + : MSanOptions(TrackOrigins, Recover, EnableKmsan) {} + + PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); + MemorySanitizerOptions MSanOptions; +}; + } // end namespace llvm #endif // LLVM_TRANSFORMS_INSTRUMENTATION_H Index: llvm/lib/Passes/PassBuilder.cpp =================================================================== --- llvm/lib/Passes/PassBuilder.cpp +++ llvm/lib/Passes/PassBuilder.cpp @@ -88,6 +88,7 @@ #include "llvm/Transforms/IPO/SyntheticCountsPropagation.h" #include "llvm/Transforms/IPO/WholeProgramDevirt.h" #include "llvm/Transforms/InstCombine/InstCombine.h" +#include "llvm/Transforms/Instrumentation.h" #include "llvm/Transforms/Instrumentation/BoundsChecking.h" #include "llvm/Transforms/Instrumentation/CGProfile.h" #include "llvm/Transforms/Instrumentation/ControlHeightReduction.h" Index: llvm/lib/Passes/PassRegistry.def =================================================================== --- llvm/lib/Passes/PassRegistry.def +++ llvm/lib/Passes/PassRegistry.def @@ -81,6 +81,7 @@ MODULE_PASS("synthetic-counts-propagation", SyntheticCountsPropagation()) MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass(nullptr, nullptr)) MODULE_PASS("verify", VerifierPass()) +MODULE_PASS("msan-init", MemorySanitizerInitPass()) #undef MODULE_PASS #ifndef CGSCC_ANALYSIS @@ -230,6 +231,7 @@ FUNCTION_PASS("verify", RegionInfoVerifierPass()) FUNCTION_PASS("view-cfg", CFGViewerPass()) FUNCTION_PASS("view-cfg-only", CFGOnlyViewerPass()) +FUNCTION_PASS("msan", MemorySanitizerPass()) #undef FUNCTION_PASS #ifndef LOOP_ANALYSIS Index: llvm/lib/Transforms/Instrumentation/Instrumentation.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/Instrumentation.cpp +++ llvm/lib/Transforms/Instrumentation/Instrumentation.cpp @@ -111,7 +111,7 @@ initializePGOIndirectCallPromotionLegacyPassPass(Registry); initializePGOMemOPSizeOptLegacyPassPass(Registry); initializeInstrProfilingLegacyPassPass(Registry); - initializeMemorySanitizerPass(Registry); + initializeMemorySanitizerLegacyPassPass(Registry); initializeHWAddressSanitizerPass(Registry); initializeThreadSanitizerPass(Registry); initializeSanitizerCoverageModulePass(Registry); Index: llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp =================================================================== --- llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -452,50 +452,32 @@ /// /// 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, MemorySanitizerOptions MSanOptions) + : MSanOptions(MSanOptions) { + initializeModule(M); } + MemorySanitizer(Module &M, int TrackOrigins = 0, bool Recover = false, + bool EnableKmsan = false) + : MemorySanitizer(M, {TrackOrigins, Recover, EnableKmsan}) {} - bool runOnFunction(Function &F) override; - bool doInitialization(Module &M) override; + bool sanitizeFunction(Function &F, TargetLibraryInfo &TLI); private: + friend struct MemorySanitizerLegacyPass; friend struct MemorySanitizerVisitor; friend struct VarArgAMD64Helper; friend struct VarArgMIPS64Helper; friend struct VarArgAArch64Helper; friend struct VarArgPowerPC64Helper; + void initializeModule(Module &M); void initializeCallbacks(Module &M); void createKernelApi(Module &M); void createUserspaceApi(Module &M); - /// True if we're compiling the Linux kernel. - bool CompileKernel; - - /// Track origins (allocation points) of uninitialized values. - int TrackOrigins; - bool Recover; + MemorySanitizerOptions MSanOptions; LLVMContext *C; Type *IntptrTy; @@ -589,25 +571,58 @@ /// An empty volatile inline asm that prevents callback merge. InlineAsm *EmptyAsm; +}; + +struct MemorySanitizerLegacyPass : public 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 "MemorySanitizerLegacyPass"; } + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + } - Function *MsanCtorFunction; + bool runOnFunction(Function &F) override { + return MSan->sanitizeFunction( + F, getAnalysis().getTLI()); + } + bool doInitialization(Module &M) override; + + std::unique_ptr MSan; + int TrackOrigins; + bool Recover; + bool EnableKmsan; }; } // end anonymous namespace -char MemorySanitizer::ID = 0; +PreservedAnalyses MemorySanitizerPass::run(Function &F, + FunctionAnalysisManager &FAM) { + MemorySanitizer Msan(*F.getParent(), MSanOptions); + if (Msan.sanitizeFunction(F, FAM.getResult(F))) + return PreservedAnalyses::none(); + return PreservedAnalyses::all(); +} -INITIALIZE_PASS_BEGIN( - MemorySanitizer, "msan", - "MemorySanitizer: detects uninitialized reads.", false, false) -INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) -INITIALIZE_PASS_END( - MemorySanitizer, "msan", - "MemorySanitizer: detects uninitialized reads.", false, false) +char MemorySanitizerLegacyPass::ID = 0; -FunctionPass *llvm::createMemorySanitizerPass(int TrackOrigins, bool Recover, - bool CompileKernel) { - return new MemorySanitizer(TrackOrigins, Recover, CompileKernel); +INITIALIZE_PASS_BEGIN(MemorySanitizerLegacyPass, "msan", + "MemorySanitizer: detects uninitialized reads.", false, + false) +INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) +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); } /// Create a non-const global initialized with the given string. @@ -684,51 +699,67 @@ "__msan_unpoison_alloca", IRB.getVoidTy(), IRB.getInt8PtrTy(), IntptrTy); } +static GlobalVariable *getOrCreateGlobalVariable( + Module &M, Type *Ty, bool isConstant, GlobalValue::LinkageTypes Linkage, + Constant *Initializer, const Twine &Name = "", + GlobalVariable *InsertBefore = nullptr, + GlobalValue::ThreadLocalMode TLM = GlobalValue::NotThreadLocal, + unsigned AddressSpace = 0, bool isExternallyInitialized = false) { + std::string GVName = Name.str(); + if (!GVName.empty()) + if (auto *GV = M.getGlobalVariable(GVName)) + if (GV->getType()->getPointerElementType() == Ty) + return GV; + return new GlobalVariable(M, Ty, isConstant, Linkage, Initializer, Name, + InsertBefore, TLM, AddressSpace, + isExternallyInitialized); +} + /// Insert declarations for userspace-specific functions and globals. void MemorySanitizer::createUserspaceApi(Module &M) { IRBuilder<> IRB(*C); // Create the callback. // FIXME: this function should have "Cold" calling conv, // which is not yet implemented. - StringRef WarningFnName = Recover ? "__msan_warning" - : "__msan_warning_noreturn"; + StringRef WarningFnName = + MSanOptions.Recover ? "__msan_warning" : "__msan_warning_noreturn"; WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy()); // Create the global TLS variables. - RetvalTLS = new GlobalVariable( + RetvalTLS = getOrCreateGlobalVariable( M, ArrayType::get(IRB.getInt64Ty(), kRetvalTLSSize / 8), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_retval_tls", nullptr, GlobalVariable::InitialExecTLSModel); - RetvalOriginTLS = new GlobalVariable( + RetvalOriginTLS = getOrCreateGlobalVariable( M, OriginTy, false, GlobalVariable::ExternalLinkage, nullptr, "__msan_retval_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel); - ParamTLS = new GlobalVariable( + ParamTLS = getOrCreateGlobalVariable( M, ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_param_tls", nullptr, GlobalVariable::InitialExecTLSModel); - ParamOriginTLS = new GlobalVariable( + ParamOriginTLS = getOrCreateGlobalVariable( M, ArrayType::get(OriginTy, kParamTLSSize / 4), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_param_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel); - VAArgTLS = new GlobalVariable( + VAArgTLS = getOrCreateGlobalVariable( M, ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_va_arg_tls", nullptr, GlobalVariable::InitialExecTLSModel); - VAArgOriginTLS = new GlobalVariable( + VAArgOriginTLS = getOrCreateGlobalVariable( M, ArrayType::get(OriginTy, kParamTLSSize / 4), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_va_arg_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel); - VAArgOverflowSizeTLS = new GlobalVariable( + VAArgOverflowSizeTLS = getOrCreateGlobalVariable( M, IRB.getInt64Ty(), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_va_arg_overflow_size_tls", nullptr, GlobalVariable::InitialExecTLSModel); - OriginTLS = new GlobalVariable( + OriginTLS = getOrCreateGlobalVariable( M, IRB.getInt32Ty(), false, GlobalVariable::ExternalLinkage, nullptr, "__msan_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel); @@ -786,7 +817,7 @@ M.getOrInsertFunction("__msan_instrument_asm_store", IRB.getVoidTy(), PointerType::get(IRB.getInt8Ty(), 0), IntptrTy); - if (CompileKernel) { + if (MSanOptions.CompileKernel) { createKernelApi(M); } else { createUserspaceApi(M); @@ -812,9 +843,7 @@ } /// Module-level initialization. -/// -/// inserts a call to __msan_init to the module's constructor list. -bool MemorySanitizer::doInitialization(Module &M) { +void MemorySanitizer::initializeModule(Module &M) { auto &DL = M.getDataLayout(); bool ShadowPassed = ClShadowBase.getNumOccurrences() > 0; @@ -886,29 +915,61 @@ ColdCallWeights = MDBuilder(*C).createBranchWeights(1, 1000); 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); - } +static bool createGlobals(Module &M, + const MemorySanitizerOptions &MSanOptions) { + if (MSanOptions.CompileKernel) + return false; + 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); + } - if (TrackOrigins) - new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, - IRB.getInt32(TrackOrigins), "__msan_track_origins"); + IRBuilder<> IRB(M.getContext()); + if (MSanOptions.TrackOrigins) + getOrCreateGlobalVariable( + M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, + IRB.getInt32(MSanOptions.TrackOrigins), "__msan_track_origins"); - if (Recover) - new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, - IRB.getInt32(Recover), "__msan_keep_going"); - } + if (MSanOptions.Recover) + getOrCreateGlobalVariable( + M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage, + IRB.getInt32(MSanOptions.Recover), "__msan_keep_going"); + return true; +} + +MemorySanitizerOptions::MemorySanitizerOptions(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); +} + +PreservedAnalyses MemorySanitizerInitPass::run(Module &M, + ModuleAnalysisManager &MAM) { + if (createGlobals(M, MSanOptions)) + return PreservedAnalyses::none(); + return PreservedAnalyses::all(); +} + +bool MemorySanitizerLegacyPass::doInitialization(Module &M) { + MSan = make_unique(M, TrackOrigins, Recover, EnableKmsan); + createGlobals(M, MSan->MSanOptions); return true; } @@ -989,8 +1050,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; @@ -999,10 +1061,9 @@ // 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) + if (MS.MSanOptions.CompileKernel) ActualFnStart = insertKmsanPrologue(F); else ActualFnStart = &F.getEntryBlock(); @@ -1013,7 +1074,8 @@ } Value *updateOrigin(Value *V, IRBuilder<> &IRB) { - if (MS.TrackOrigins <= 1) return V; + if (MS.MSanOptions.TrackOrigins <= 1) + return V; return IRB.CreateCall(MS.MsanChainOriginFn, V); } @@ -1079,7 +1141,8 @@ unsigned TypeSizeInBits = DL.getTypeSizeInBits(ConvertedShadow->getType()); unsigned SizeIndex = TypeSizeToSizeIndex(TypeSizeInBits); - if (AsCall && SizeIndex < kNumberOfAccessSizes && !MS.CompileKernel) { + if (AsCall && SizeIndex < kNumberOfAccessSizes && + !MS.MSanOptions.CompileKernel) { Value *Fn = MS.MaybeStoreOriginFn[SizeIndex]; Value *ConvertedShadow2 = IRB.CreateZExt( ConvertedShadow, IRB.getIntNTy(8 * (1 << SizeIndex))); @@ -1118,7 +1181,7 @@ if (SI->isAtomic()) SI->setOrdering(addReleaseOrdering(SI->getOrdering())); - if (MS.TrackOrigins && !SI->isAtomic()) + if (MS.MSanOptions.TrackOrigins && !SI->isAtomic()) storeOrigin(IRB, Addr, Shadow, getOrigin(Val), OriginPtr, OriginAlignment, InstrumentWithCalls); } @@ -1128,10 +1191,10 @@ void insertWarningFn(IRBuilder<> &IRB, Value *Origin) { if (!Origin) Origin = (Value *)IRB.getInt32(0); - if (MS.CompileKernel) { + if (MS.MSanOptions.CompileKernel) { IRB.CreateCall(MS.WarningFn, Origin); } else { - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { IRB.CreateStore(Origin, MS.OriginTLS); } IRB.CreateCall(MS.WarningFn, {}); @@ -1161,19 +1224,21 @@ unsigned TypeSizeInBits = DL.getTypeSizeInBits(ConvertedShadow->getType()); unsigned SizeIndex = TypeSizeToSizeIndex(TypeSizeInBits); - if (AsCall && SizeIndex < kNumberOfAccessSizes && !MS.CompileKernel) { + if (AsCall && SizeIndex < kNumberOfAccessSizes && + !MS.MSanOptions.CompileKernel) { Value *Fn = MS.MaybeWarningFn[SizeIndex]; Value *ConvertedShadow2 = IRB.CreateZExt(ConvertedShadow, IRB.getIntNTy(8 * (1 << SizeIndex))); - IRB.CreateCall(Fn, {ConvertedShadow2, MS.TrackOrigins && Origin - ? Origin - : (Value *)IRB.getInt32(0)}); + IRB.CreateCall(Fn, + {ConvertedShadow2, MS.MSanOptions.TrackOrigins && Origin + ? Origin + : (Value *)IRB.getInt32(0)}); } else { Value *Cmp = IRB.CreateICmpNE(ConvertedShadow, getCleanShadow(ConvertedShadow), "_mscmp"); Instruction *CheckTerm = SplitBlockAndInsertIfThen( Cmp, OrigIns, - /* Unreachable */ !MS.Recover, MS.ColdCallWeights); + /* Unreachable */ !MS.MSanOptions.Recover, MS.ColdCallWeights); IRB.SetInsertPoint(CheckTerm); insertWarningFn(IRB, Origin); @@ -1231,7 +1296,8 @@ // Finalize PHI nodes. for (PHINode *PN : ShadowPHINodes) { PHINode *PNS = cast(getShadow(PN)); - PHINode *PNO = MS.TrackOrigins ? cast(getOrigin(PN)) : nullptr; + PHINode *PNO = + MS.MSanOptions.TrackOrigins ? cast(getOrigin(PN)) : nullptr; size_t NumValues = PN->getNumIncomingValues(); for (size_t v = 0; v < NumValues; v++) { PNS->addIncoming(getShadow(PN, v), PN->getIncomingBlock(v)); @@ -1339,13 +1405,12 @@ uint64_t ShadowBase = MS.MapParams->ShadowBase; if (ShadowBase != 0) { ShadowLong = - IRB.CreateAdd(ShadowLong, - ConstantInt::get(MS.IntptrTy, ShadowBase)); + IRB.CreateAdd(ShadowLong, ConstantInt::get(MS.IntptrTy, ShadowBase)); } Value *ShadowPtr = IRB.CreateIntToPtr(ShadowLong, PointerType::get(ShadowTy, 0)); Value *OriginPtr = nullptr; - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { Value *OriginLong = ShadowOffset; uint64_t OriginBase = MS.MapParams->OriginBase; if (OriginBase != 0) @@ -1392,7 +1457,7 @@ unsigned Alignment, bool isStore) { std::pair ret; - if (MS.CompileKernel) + if (MS.MSanOptions.CompileKernel) ret = getShadowOriginPtrKernel(Addr, IRB, ShadowTy, Alignment, isStore); else ret = getShadowOriginPtrUserspace(Addr, IRB, ShadowTy, Alignment); @@ -1412,9 +1477,8 @@ } /// Compute the origin address for a given function argument. - Value *getOriginPtrForArgument(Value *A, IRBuilder<> &IRB, - int ArgOffset) { - if (!MS.TrackOrigins) + Value *getOriginPtrForArgument(Value *A, IRBuilder<> &IRB, int ArgOffset) { + if (!MS.MSanOptions.TrackOrigins) return nullptr; Value *Base = IRB.CreatePointerCast(MS.ParamOriginTLS, MS.IntptrTy); if (ArgOffset) @@ -1444,7 +1508,8 @@ /// Set Origin to be the origin value for V. void setOrigin(Value *V, Value *Origin) { - if (!MS.TrackOrigins) return; + if (!MS.MSanOptions.TrackOrigins) + return; assert(!OriginMap.count(V) && "Values may only have one origin"); LLVM_DEBUG(dbgs() << "ORIGIN: " << *V << " ==> " << *Origin << "\n"); OriginMap[V] = Origin; @@ -1580,7 +1645,7 @@ } LLVM_DEBUG(dbgs() << " ARG: " << FArg << " ==> " << **ShadowPtr << "\n"); - if (MS.TrackOrigins && !Overflow) { + if (MS.MSanOptions.TrackOrigins && !Overflow) { Value *OriginPtr = getOriginPtrForArgument(&FArg, EntryIRB, ArgOffset); setOrigin(A, EntryIRB.CreateLoad(OriginPtr)); @@ -1604,7 +1669,8 @@ /// Get the origin for a value. Value *getOrigin(Value *V) { - if (!MS.TrackOrigins) return nullptr; + if (!MS.MSanOptions.TrackOrigins) + return nullptr; if (!PropagateShadow) return getCleanOrigin(); if (isa(V)) return getCleanOrigin(); assert((isa(V) || isa(V)) && @@ -1725,7 +1791,7 @@ if (I.isAtomic()) I.setOrdering(addAcquireOrdering(I.getOrdering())); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { if (PropagateShadow) { unsigned OriginAlignment = std::max(kMinOriginAlignment, Alignment); setOrigin(&I, IRB.CreateAlignedLoad(OriginPtr, OriginAlignment)); @@ -1943,7 +2009,7 @@ } } - if (MSV->MS.TrackOrigins) { + if (MSV->MS.MSanOptions.TrackOrigins) { assert(OpOrigin); if (!Origin) { Origin = OpOrigin; @@ -1964,7 +2030,8 @@ /// Add an application value to the mix. Combiner &Add(Value *V) { Value *OpShadow = MSV->getShadow(V); - Value *OpOrigin = MSV->MS.TrackOrigins ? MSV->getOrigin(V) : nullptr; + Value *OpOrigin = + MSV->MS.MSanOptions.TrackOrigins ? MSV->getOrigin(V) : nullptr; return Add(OpShadow, OpOrigin); } @@ -1976,7 +2043,7 @@ Shadow = MSV->CreateShadowCast(IRB, Shadow, MSV->getShadowTy(I)); MSV->setShadow(I, Shadow); } - if (MSV->MS.TrackOrigins) { + if (MSV->MS.MSanOptions.TrackOrigins) { assert(Origin); MSV->setOrigin(I, Origin); } @@ -1988,7 +2055,8 @@ /// Propagate origin for arbitrary operation. void setOriginForNaryOp(Instruction &I) { - if (!MS.TrackOrigins) return; + if (!MS.MSanOptions.TrackOrigins) + return; IRBuilder<> IRB(&I); OriginCombiner OC(this, IRB); for (Instruction::op_iterator OI = I.op_begin(); OI != I.op_end(); ++OI) @@ -2388,7 +2456,8 @@ insertShadowCheck(Addr, &I); // FIXME: factor out common code from materializeStores - if (MS.TrackOrigins) IRB.CreateStore(getOrigin(&I, 1), OriginPtr); + if (MS.MSanOptions.TrackOrigins) + IRB.CreateStore(getOrigin(&I, 1), OriginPtr); return true; } @@ -2416,7 +2485,7 @@ if (ClCheckAccessAddress) insertShadowCheck(Addr, &I); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { if (PropagateShadow) setOrigin(&I, IRB.CreateLoad(OriginPtr)); else @@ -2802,8 +2871,8 @@ insertShadowCheck(Addr, &I); Value *Shadow = IRB.CreateAlignedLoad(ShadowPtr, Alignment, "_ldmxcsr"); - Value *Origin = - MS.TrackOrigins ? IRB.CreateLoad(OriginPtr) : getCleanOrigin(); + Value *Origin = MS.MSanOptions.TrackOrigins ? IRB.CreateLoad(OriginPtr) + : getCleanOrigin(); insertShadowCheck(Shadow, Origin, &I); } @@ -2829,7 +2898,7 @@ IRB.CreateMaskedStore(Shadow, ShadowPtr, Align, Mask); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { auto &DL = F.getParent()->getDataLayout(); paintOrigin(IRB, getOrigin(V), OriginPtr, DL.getTypeStoreSize(Shadow->getType()), @@ -2860,7 +2929,7 @@ insertShadowCheck(Mask, &I); } - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { if (PropagateShadow) { // Choose between PassThru's and the loaded value's origins. Value *MaskedPassThruShadow = IRB.CreateAnd( @@ -3121,7 +3190,7 @@ // outputs as clean. Note that any side effects of the inline asm that are // not immediately visible in its constraints are not handled. if (Call->isInlineAsm()) { - if (ClHandleAsmConservative && MS.CompileKernel) + if (ClHandleAsmConservative && MS.MSanOptions.CompileKernel) visitAsmInstruction(I); else visitInstruction(I); @@ -3184,13 +3253,15 @@ // TODO(glider): need to copy origins. } else { Size = DL.getTypeAllocSize(A->getType()); - if (ArgOffset + Size > kParamTLSSize) break; + if (ArgOffset + Size > kParamTLSSize) + break; Store = IRB.CreateAlignedStore(ArgShadow, ArgShadowBase, kShadowTLSAlignment); Constant *Cst = dyn_cast(ArgShadow); - if (Cst && Cst->isNullValue()) ArgIsInitialized = true; + if (Cst && Cst->isNullValue()) + ArgIsInitialized = true; } - if (MS.TrackOrigins && !ArgIsInitialized) + if (MS.MSanOptions.TrackOrigins && !ArgIsInitialized) IRB.CreateStore(getOrigin(A), getOriginPtrForArgument(A, IRB, ArgOffset)); (void)Store; @@ -3228,18 +3299,17 @@ setOrigin(&I, getCleanOrigin()); return; } - // FIXME: NextInsn is likely in a basic block that has not been visited yet. - // Anything inserted there will be instrumented by MSan later! + // FIXME: NextInsn is likely in a basic block that has not been visited + // yet. Anything inserted there will be instrumented by MSan later! NextInsn = NormalDest->getFirstInsertionPt(); assert(NextInsn != NormalDest->end() && "Could not find insertion point for retval shadow load"); } IRBuilder<> IRBAfter(&*NextInsn); - Value *RetvalShadow = - IRBAfter.CreateAlignedLoad(getShadowPtrForRetval(&I, IRBAfter), - kShadowTLSAlignment, "_msret"); + Value *RetvalShadow = IRBAfter.CreateAlignedLoad( + getShadowPtrForRetval(&I, IRBAfter), kShadowTLSAlignment, "_msret"); setShadow(&I, RetvalShadow); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) setOrigin(&I, IRBAfter.CreateLoad(getOriginPtrForRetval(IRBAfter))); } @@ -3267,7 +3337,7 @@ } else { Value *Shadow = getShadow(RetVal); IRB.CreateAlignedStore(Shadow, ShadowPtr, kShadowTLSAlignment); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) IRB.CreateStore(getOrigin(RetVal), getOriginPtrForRetval(IRB)); } } @@ -3283,7 +3353,7 @@ ShadowPHINodes.push_back(&I); setShadow(&I, IRB.CreatePHI(getShadowTy(&I), I.getNumIncomingValues(), "_msphi_s")); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) setOrigin(&I, IRB.CreatePHI(MS.OriginTy, I.getNumIncomingValues(), "_msphi_o")); } @@ -3314,7 +3384,7 @@ IRB.CreateMemSet(ShadowBase, PoisonValue, Len, I.getAlignment()); } - if (PoisonStack && MS.TrackOrigins) { + if (PoisonStack && MS.MSanOptions.TrackOrigins) { Value *Descr = getLocalVarDescription(I); IRB.CreateCall(MS.MsanSetAllocaOrigin4Fn, {IRB.CreatePointerCast(&I, IRB.getInt8PtrTy()), Len, @@ -3345,7 +3415,7 @@ if (I.isArrayAllocation()) Len = IRB.CreateMul(Len, I.getArraySize()); - if (MS.CompileKernel) + if (MS.MSanOptions.CompileKernel) instrumentAllocaKmsan(I, IRB, Len); else instrumentAllocaUserspace(I, IRB, Len); @@ -3384,7 +3454,7 @@ } Value *Sa = IRB.CreateSelect(Sb, Sa1, Sa0, "_msprop_select"); setShadow(&I, Sa); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { // Origins are always i32, so any vector conditions must be flattened. // FIXME: consider tracking vector origins for app vectors? if (B->getType()->isVectorTy()) { @@ -3659,7 +3729,7 @@ Value *ShadowBase = getShadowPtrForVAArgument( RealTy, IRB, OverflowOffset, alignTo(ArgSize, 8)); Value *OriginBase = nullptr; - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) OriginBase = getOriginPtrForVAArgument(RealTy, IRB, OverflowOffset); OverflowOffset += alignTo(ArgSize, 8); if (!ShadowBase) @@ -3671,7 +3741,7 @@ IRB.CreateMemCpy(ShadowBase, kShadowTLSAlignment, ShadowPtr, kShadowTLSAlignment, ArgSize); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) IRB.CreateMemCpy(OriginBase, kShadowTLSAlignment, OriginPtr, kShadowTLSAlignment, ArgSize); } else { @@ -3685,7 +3755,7 @@ case AK_GeneralPurpose: ShadowBase = getShadowPtrForVAArgument(A->getType(), IRB, GpOffset, 8); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) OriginBase = getOriginPtrForVAArgument(A->getType(), IRB, GpOffset); GpOffset += 8; @@ -3693,7 +3763,7 @@ case AK_FloatingPoint: ShadowBase = getShadowPtrForVAArgument(A->getType(), IRB, FpOffset, 16); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) OriginBase = getOriginPtrForVAArgument(A->getType(), IRB, FpOffset); FpOffset += 16; @@ -3704,7 +3774,7 @@ uint64_t ArgSize = DL.getTypeAllocSize(A->getType()); ShadowBase = getShadowPtrForVAArgument(A->getType(), IRB, OverflowOffset, 8); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) OriginBase = getOriginPtrForVAArgument(A->getType(), IRB, OverflowOffset); OverflowOffset += alignTo(ArgSize, 8); @@ -3718,7 +3788,7 @@ continue; Value *Shadow = MSV.getShadow(A); IRB.CreateAlignedStore(Shadow, ShadowBase, kShadowTLSAlignment); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { Value *Origin = MSV.getOrigin(A); unsigned StoreSize = DL.getTypeStoreSize(Shadow->getType()); MSV.paintOrigin(IRB, Origin, OriginBase, StoreSize, @@ -3796,7 +3866,7 @@ VAArgOverflowSize); VAArgTLSCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize); IRB.CreateMemCpy(VAArgTLSCopy, 8, MS.VAArgTLS, 8, CopySize); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { VAArgTLSOriginCopy = IRB.CreateAlloca(Type::getInt8Ty(*MS.C), CopySize); IRB.CreateMemCpy(VAArgTLSOriginCopy, 8, MS.VAArgOriginTLS, 8, CopySize); } @@ -3821,7 +3891,7 @@ Alignment, /*isStore*/ true); IRB.CreateMemCpy(RegSaveAreaShadowPtr, Alignment, VAArgTLSCopy, Alignment, AMD64FpEndOffset); - if (MS.TrackOrigins) + if (MS.MSanOptions.TrackOrigins) IRB.CreateMemCpy(RegSaveAreaOriginPtr, Alignment, VAArgTLSOriginCopy, Alignment, AMD64FpEndOffset); Value *OverflowArgAreaPtrPtr = IRB.CreateIntToPtr( @@ -3837,7 +3907,7 @@ AMD64FpEndOffset); IRB.CreateMemCpy(OverflowArgAreaShadowPtr, Alignment, SrcPtr, Alignment, VAArgOverflowSize); - if (MS.TrackOrigins) { + if (MS.MSanOptions.TrackOrigins) { SrcPtr = IRB.CreateConstGEP1_32(IRB.getInt8Ty(), VAArgTLSOriginCopy, AMD64FpEndOffset); IRB.CreateMemCpy(OverflowArgAreaOriginPtr, Alignment, SrcPtr, Alignment, @@ -3858,7 +3928,8 @@ SmallVector VAStartInstrumentationList; VarArgMIPS64Helper(Function &F, MemorySanitizer &MS, - MemorySanitizerVisitor &MSV) : F(F), MS(MS), MSV(MSV) {} + MemorySanitizerVisitor &MSV) + : F(F), MS(MS), MSV(MSV) {} void visitCallSite(CallSite &CS, IRBuilder<> &IRB) override { unsigned VAArgOffset = 0; @@ -3986,7 +4057,8 @@ enum ArgKind { AK_GeneralPurpose, AK_FloatingPoint, AK_Memory }; VarArgAArch64Helper(Function &F, MemorySanitizer &MS, - MemorySanitizerVisitor &MSV) : F(F), MS(MS), MSV(MSV) {} + MemorySanitizerVisitor &MSV) + : F(F), MS(MS), MSV(MSV) {} ArgKind classifyArgument(Value* arg) { Type *T = arg->getType(); @@ -4231,7 +4303,8 @@ SmallVector VAStartInstrumentationList; VarArgPowerPC64Helper(Function &F, MemorySanitizer &MS, - MemorySanitizerVisitor &MSV) : F(F), MS(MS), MSV(MSV) {} + MemorySanitizerVisitor &MSV) + : F(F), MS(MS), MSV(MSV) {} void visitCallSite(CallSite &CS, IRBuilder<> &IRB) override { // For PowerPC, we need to deal with alignment of stack arguments - @@ -4430,15 +4503,14 @@ return new VarArgNoOpHelper(Func, Msan, Visitor); } -bool MemorySanitizer::runOnFunction(Function &F) { - if (!CompileKernel && (&F == MsanCtorFunction)) +bool MemorySanitizer::sanitizeFunction(Function &F, TargetLibraryInfo &TLI) { + if (!MSanOptions.CompileKernel && (F.getName() == kMsanModuleCtorName)) return false; - MemorySanitizerVisitor Visitor(F, *this); + MemorySanitizerVisitor Visitor(F, *this, TLI); // Clear out readonly/readnone attributes. AttrBuilder B; - B.addAttribute(Attribute::ReadOnly) - .addAttribute(Attribute::ReadNone); + B.addAttribute(Attribute::ReadOnly).addAttribute(Attribute::ReadNone); F.removeAttributes(AttributeList::FunctionIndex, B); return Visitor.runOnFunction(); Index: llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll +++ llvm/test/Instrumentation/MemorySanitizer/AArch64/vararg.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes='msan-init,function(msan)' 2>&1 | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128" Index: llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll +++ llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes='msan-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll +++ llvm/test/Instrumentation/MemorySanitizer/Mips/vararg-mips64el.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes='msan-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll +++ llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes='msan-init,function(msan)' 2>&1 | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "E-m:e-i64:64-n32:64" Index: llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll +++ llvm/test/Instrumentation/MemorySanitizer/PowerPC/vararg-ppc64le.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes='msan-init,function(msan)' 2>&1 | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s target datalayout = "e-m:e-i64:64-n32:64" Index: llvm/test/Instrumentation/MemorySanitizer/X86/vararg-too-large.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/X86/vararg-too-large.ll +++ llvm/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-init,function(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: llvm/test/Instrumentation/MemorySanitizer/X86/vararg.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/X86/vararg.ll +++ llvm/test/Instrumentation/MemorySanitizer/X86/vararg.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 ; RUN: opt < %s -msan -msan-check-access-address=0 -S ; Test that code using va_start can be compiled on i386. Index: llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll +++ llvm/test/Instrumentation/MemorySanitizer/X86/vararg_call.ll @@ -1,5 +1,11 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/alloca.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/alloca.ll +++ llvm/test/Instrumentation/MemorySanitizer/alloca.ll @@ -1,7 +1,17 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s "--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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/array_types.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/array_types.ll +++ llvm/test/Instrumentation/MemorySanitizer/array_types.ll @@ -1,4 +1,9 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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-init,function(msan)' 2>&1 | FileCheck -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS %s --allow-empty ; 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: llvm/test/Instrumentation/MemorySanitizer/atomics.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/atomics.ll +++ llvm/test/Instrumentation/MemorySanitizer/atomics.ll @@ -1,5 +1,11 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/byval-alignment.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/byval-alignment.ll +++ llvm/test/Instrumentation/MemorySanitizer/byval-alignment.ll @@ -1,5 +1,7 @@ ; 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-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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: llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/check-constant-shadow.ll +++ llvm/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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll +++ llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=1 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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: llvm/test/Instrumentation/MemorySanitizer/csr.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/csr.ll +++ llvm/test/Instrumentation/MemorySanitizer/csr.ll @@ -1,4 +1,8 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s +; RUN: opt < %s -msan-check-access-address=1 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s --check-prefix=ADDR ; RUN: opt < %s -msan -msan-check-access-address=1 -S | FileCheck %s --check-prefix=ADDR ; REQUIRES: x86-registered-target Index: llvm/test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll +++ llvm/test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll @@ -1,4 +1,5 @@ ; MSan converts 2-element global_ctors to 3-element when adding the new entry. +; RUN: opt < %s -msan-with-comdat -S -passes='msan-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/instrumentation-with-call-threshold.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/instrumentation-with-call-threshold.ll +++ llvm/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-init,function(msan)' 2>&1 | \ +; RUN: FileCheck %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-init,function(msan)' 2>&1 | FileCheck -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS %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-init,function(msan)' 2>&1 | FileCheck -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS %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: llvm/test/Instrumentation/MemorySanitizer/manual-shadow.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/manual-shadow.ll +++ llvm/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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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-init,function(msan)'\ +; RUN: 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/masked-store-load.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/masked-store-load.ll +++ llvm/test/Instrumentation/MemorySanitizer/masked-store-load.ll @@ -1,5 +1,11 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s --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: llvm/test/Instrumentation/MemorySanitizer/missing_origin.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/missing_origin.ll +++ llvm/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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/msan_asm_conservative.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/msan_asm_conservative.ll +++ llvm/test/Instrumentation/MemorySanitizer/msan_asm_conservative.ll @@ -1,5 +1,11 @@ ; Test for handling of asm constraints in MSan instrumentation. +; RUN: opt < %s -msan-kernel=1 -msan-check-access-address=0 \ +; RUN: -msan-handle-asm-conservative=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: "-check-prefixes=CHECK,CHECK-NONCONS" %s ; RUN: opt < %s -msan -msan-kernel=1 -msan-check-access-address=0 -msan-handle-asm-conservative=0 -S | FileCheck -check-prefixes=CHECK,CHECK-NONCONS %s +; RUN: opt < %s -msan-kernel=1 -msan-check-access-address=0 \ +; RUN: -msan-handle-asm-conservative=1 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: "-check-prefixes=CHECK,CHECK-CONS" %s ; RUN: opt < %s -msan -msan-kernel=1 -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: llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll +++ llvm/test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -1,4 +1,9 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: -allow-deprecated-dag-overlap %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck -allow-deprecated-dag-overlap %s +; RUN: opt < %s -msan-check-access-address=0 -msan-track-origins=1 -S \ +; RUN: -passes='msan-init,function(msan)' 2>&1 | 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 | FileCheck -allow-deprecated-dag-overlap -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: llvm/test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll +++ llvm/test/Instrumentation/MemorySanitizer/msan_kernel_basic.ll @@ -1,4 +1,6 @@ ; KMSAN instrumentation tests +; RUN: opt < %s -msan-kernel=1 -S -passes='msan-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/msan_x86_bts_asm.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/msan_x86_bts_asm.ll +++ llvm/test/Instrumentation/MemorySanitizer/msan_x86_bts_asm.ll @@ -1,5 +1,11 @@ ; Test for the conservative assembly handling mode used by KMSAN. +; RUN: opt < %s -msan-kernel=1 -msan-check-access-address=0 \ +; RUN: -msan-handle-asm-conservative=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: "-check-prefixes=CHECK,CHECK-NONCONS" %s ; RUN: opt < %s -msan -msan-kernel=1 -msan-check-access-address=0 -msan-handle-asm-conservative=0 -S | FileCheck -check-prefixes=CHECK,CHECK-NONCONS %s +; RUN: opt < %s -msan-kernel=1 -msan-check-access-address=0 \ +; RUN: -msan-handle-asm-conservative=1 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: "-check-prefixes=CHECK,CHECK-CONS" %s ; RUN: opt < %s -msan -msan-kernel=1 -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: llvm/test/Instrumentation/MemorySanitizer/msan_x86intrinsics.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/msan_x86intrinsics.ll +++ llvm/test/Instrumentation/MemorySanitizer/msan_x86intrinsics.ll @@ -1,4 +1,9 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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-init,function(msan)' 2>&1 | FileCheck -check-prefix=CHECK \ +; RUN: -check-prefix=CHECK-ORIGINS %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: llvm/test/Instrumentation/MemorySanitizer/mul_by_constant.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/mul_by_constant.ll +++ llvm/test/Instrumentation/MemorySanitizer/mul_by_constant.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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: llvm/test/Instrumentation/MemorySanitizer/nosanitize.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/nosanitize.ll +++ llvm/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-init,function(msan)' 2>&1 | FileCheck %s ; RUN: opt < %s -msan -S | FileCheck %s +; RUN: opt < %s -msan-track-origins=1 -S -passes='msan-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/origin-alignment.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/origin-alignment.ll +++ llvm/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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/origin-array.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/origin-array.ll +++ llvm/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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/pr32842.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/pr32842.ll +++ llvm/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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/return_from_main.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/return_from_main.ll +++ llvm/test/Instrumentation/MemorySanitizer/return_from_main.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %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: llvm/test/Instrumentation/MemorySanitizer/store-long-origin.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/store-long-origin.ll +++ llvm/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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/store-origin.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/store-origin.ll +++ llvm/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-init,function(msan)' 2>&1 | 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-init,function(msan)' 2>&1 | 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-init,function(msan)' \ +; RUN: 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/str-nobuiltin.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/str-nobuiltin.ll +++ llvm/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-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/unreachable.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/unreachable.ll +++ llvm/test/Instrumentation/MemorySanitizer/unreachable.ll @@ -1,3 +1,4 @@ +; RUN: opt < %s -S -passes='msan-init,function(msan)' 2>&1 | 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: llvm/test/Instrumentation/MemorySanitizer/unsized_type.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/unsized_type.ll +++ llvm/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-init,function(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: llvm/test/Instrumentation/MemorySanitizer/vector_arith.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/vector_arith.ll +++ llvm/test/Instrumentation/MemorySanitizer/vector_arith.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: llvm/test/Instrumentation/MemorySanitizer/vector_cmp.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/vector_cmp.ll +++ llvm/test/Instrumentation/MemorySanitizer/vector_cmp.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: llvm/test/Instrumentation/MemorySanitizer/vector_cvt.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/vector_cvt.ll +++ llvm/test/Instrumentation/MemorySanitizer/vector_cvt.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: llvm/test/Instrumentation/MemorySanitizer/vector_pack.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/vector_pack.ll +++ llvm/test/Instrumentation/MemorySanitizer/vector_pack.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: llvm/test/Instrumentation/MemorySanitizer/vector_shift.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/vector_shift.ll +++ llvm/test/Instrumentation/MemorySanitizer/vector_shift.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-check-access-address=0 -S -passes='msan-init,function(msan)' 2>&1 | FileCheck \ +; RUN: %s ; RUN: opt < %s -msan -msan-check-access-address=0 -S | FileCheck %s ; REQUIRES: x86-registered-target Index: llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll =================================================================== --- llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll +++ llvm/test/Instrumentation/MemorySanitizer/with-call-type-size.ll @@ -1,3 +1,5 @@ +; RUN: opt < %s -msan-instrumentation-with-call-threshold=0 -S -passes='msan-init,function(msan)' \ +; RUN: 2>&1 | 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>