diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 7828fcc432c2af64a7ebae22b7e2e12e9bde07c3..40033fc7eb0b45f360051ff71d2744f5e38e4109 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -918,9 +918,6 @@ struct MemorySanitizerVisitor : public InstVisitor { StoreInst *NewSI = IRB.CreateAlignedStore(Shadow, ShadowPtr, Alignment); LLVM_DEBUG(dbgs() << " STORE: " << *NewSI << "\n"); - if (ClCheckAccessAddress) - insertShadowCheck(Addr, NewSI); - if (SI->isAtomic()) SI->setOrdering(addReleaseOrdering(SI->getOrdering())); @@ -1024,13 +1021,13 @@ struct MemorySanitizerVisitor : public InstVisitor { InstrumentationList.size() + StoreList.size() > (unsigned)ClInstrumentationWithCallThreshold; - // Delayed instrumentation of StoreInst. - // This may add new checks to be inserted later. - materializeStores(InstrumentWithCalls); - // Insert shadow value checks. materializeChecks(InstrumentWithCalls); + // Delayed instrumentation of StoreInst. + // This may not add new address checks. + materializeStores(InstrumentWithCalls); + return true; } @@ -1490,6 +1487,8 @@ struct MemorySanitizerVisitor : public InstVisitor { /// Optionally, checks that the store address is fully defined. void visitStoreInst(StoreInst &I) { StoreList.push_back(&I); + if (ClCheckAccessAddress) + insertShadowCheck(I.getPointerOperand(), &I); } void handleCASOrRMW(Instruction &I) { diff --git a/llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll b/llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll index 38f29b71cdf1ae115475e45105a3bab400bf64b3..21bb41256061c45e3631a1ce1be5064fd23e2ced 100644 --- a/llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll +++ b/llvm/test/Instrumentation/MemorySanitizer/check_access_address.ll @@ -38,11 +38,14 @@ entry: ; CHECK-LABEL: @Store ; CHECK: load {{.*}} @__msan_param_tls +; Shadow calculations must happen after the check. +; CHECK-NOT: xor ; CHECK: icmp ; CHECK: br i1 ; CHECK: