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 @@ -3585,6 +3585,12 @@ maybeMarkSanitizerLibraryCallNoBuiltin(Call, TLI); } IRBuilder<> IRB(&CB); + bool MayCheckCall = ClEagerChecks; + if (Function *Func = CB.getCalledFunction()) { + // __sanitizer_unaligned_{load,store} functions may be called by users + // and always expects shadows in the TLS. So don't check them. + MayCheckCall &= !Func->getName().startswith("__sanitizer_unaligned"); + } unsigned ArgOffset = 0; LLVM_DEBUG(dbgs() << " CallSite: " << CB << "\n"); @@ -3610,7 +3616,7 @@ bool ByVal = CB.paramHasAttr(i, Attribute::ByVal); bool NoUndef = CB.paramHasAttr(i, Attribute::NoUndef); - bool EagerCheck = ClEagerChecks && !ByVal && NoUndef; + bool EagerCheck = MayCheckCall && !ByVal && NoUndef; if (EagerCheck) { insertShadowCheck(A, &CB); @@ -3666,7 +3672,7 @@ if (isa(CB) && cast(CB).isMustTailCall()) return; - if (ClEagerChecks && CB.hasRetAttr(Attribute::NoUndef)) { + if (MayCheckCall && CB.hasRetAttr(Attribute::NoUndef)) { setShadow(&CB, getCleanShadow(&CB)); setOrigin(&CB, getCleanOrigin()); return;