diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -2135,10 +2135,19 @@ Value *ShadowPtr = nullptr, *OriginPtr = nullptr; const Align Alignment = I.getAlign(); if (PropagateShadow) { - std::tie(ShadowPtr, OriginPtr) = + if (I.getMetadata(LLVMContext::MD_noundef)) { + IRBuilder<> IRB2(&I); + std::tie(ShadowPtr, OriginPtr) = + getShadowOriginPtr(Addr, IRB2, ShadowTy, Alignment, /*isStore*/ false); + insertShadowCheck( + IRB2.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld"), OriginPtr, &I); + setShadow(&I, getCleanShadow(&I)); + } else { + std::tie(ShadowPtr, OriginPtr) = getShadowOriginPtr(Addr, IRB, ShadowTy, Alignment, /*isStore*/ false); - setShadow(&I, - IRB.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld")); + setShadow( + &I, IRB.CreateAlignedLoad(ShadowTy, ShadowPtr, Alignment, "_msld")); + } } else { setShadow(&I, getCleanShadow(&I)); }