From b53be53c72ff7b3846f0ba990a889de444601e0b Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Wed, 26 Dec 2012 11:55:09 +0000 Subject: [PATCH] [msan] Raise alignment of origin stores/loads when possible. Origin alignment is as high as the alignment of the corresponding application location, but never less than 4. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171110 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Instrumentation/MemorySanitizer.cpp | 16 +++++++++++----- .../MemorySanitizer/msan_basic.ll | 11 +++++++++-- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 3993d887552..5a954d401eb 100644 --- a/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -100,7 +100,8 @@ static const uint64_t kShadowMask32 = 1ULL << 31; static const uint64_t kShadowMask64 = 1ULL << 46; static const uint64_t kOriginOffset32 = 1ULL << 30; static const uint64_t kOriginOffset64 = 1ULL << 45; -static const uint64_t kShadowTLSAlignment = 8; +static const unsigned kMinOriginAlignment = 4; +static const unsigned kShadowTLSAlignment = 8; /// \brief Track origins of uninitialized values. /// @@ -451,8 +452,10 @@ struct MemorySanitizerVisitor : public InstVisitor { insertCheck(Addr, &I); if (MS.TrackOrigins) { + unsigned Alignment = std::max(kMinOriginAlignment, I.getAlignment()); if (ClStoreCleanOrigin || isa(Shadow->getType())) { - IRB.CreateStore(getOrigin(Val), getOriginPtr(Addr, IRB)); + IRB.CreateAlignedStore(getOrigin(Val), getOriginPtr(Addr, IRB), + Alignment); } else { Value *ConvertedShadow = convertToShadowTyNoVec(Shadow, IRB); @@ -469,7 +472,8 @@ struct MemorySanitizerVisitor : public InstVisitor { SplitBlockAndInsertIfThen(cast(Cmp), false, MS.OriginStoreWeights); IRBuilder<> IRBNew(CheckTerm); - IRBNew.CreateStore(getOrigin(Val), getOriginPtr(Addr, IRBNew)); + IRBNew.CreateAlignedStore(getOrigin(Val), getOriginPtr(Addr, IRBNew), + Alignment); } } } @@ -827,8 +831,10 @@ struct MemorySanitizerVisitor : public InstVisitor { if (ClCheckAccessAddress) insertCheck(I.getPointerOperand(), &I); - if (MS.TrackOrigins) - setOrigin(&I, IRB.CreateLoad(getOriginPtr(Addr, IRB))); + if (MS.TrackOrigins) { + unsigned Alignment = std::max(kMinOriginAlignment, I.getAlignment()); + setOrigin(&I, IRB.CreateAlignedLoad(getOriginPtr(Addr, IRB), Alignment)); + } } /// \brief Instrument StoreInst diff --git a/test/Instrumentation/MemorySanitizer/msan_basic.ll b/test/Instrumentation/MemorySanitizer/msan_basic.ll index cd203299336..20957fb36f4 100644 --- a/test/Instrumentation/MemorySanitizer/msan_basic.ll +++ b/test/Instrumentation/MemorySanitizer/msan_basic.ll @@ -56,7 +56,7 @@ entry: ; CHECK-ORIGINS: icmp ; CHECK-ORIGINS: br i1 ; CHECK-ORIGINS: