[msan] Fix shadow & origin store & load alignment.

This change ensures that shadow memory accesses have the same alignment
as corresponding app memory accesses.

llvm-svn: 168880
This commit is contained in:
Evgeniy Stepanov 2012-11-29 14:05:53 +00:00
parent 62ba611828
commit eeb8b7c391
2 changed files with 29 additions and 4 deletions

View File

@ -710,13 +710,13 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
Type *ShadowTy = getShadowTy(&I);
Value *Addr = I.getPointerOperand();
Value *ShadowPtr = getShadowPtr(Addr, ShadowTy, IRB);
setShadow(&I, IRB.CreateLoad(ShadowPtr, "_msld"));
setShadow(&I, IRB.CreateAlignedLoad(ShadowPtr, I.getAlignment(), "_msld"));
if (ClCheckAccessAddress)
insertCheck(I.getPointerOperand(), &I);
if (ClTrackOrigins)
setOrigin(&I, IRB.CreateLoad(getOriginPtr(Addr, IRB)));
setOrigin(&I, IRB.CreateAlignedLoad(getOriginPtr(Addr, IRB), I.getAlignment()));
}
/// \brief Instrument StoreInst
@ -731,7 +731,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
Value *Shadow = getShadow(Val);
Value *ShadowPtr = getShadowPtr(Addr, Shadow->getType(), IRB);
StoreInst *NewSI = IRB.CreateStore(Shadow, ShadowPtr);
StoreInst *NewSI = IRB.CreateAlignedStore(Shadow, ShadowPtr, I.getAlignment());
DEBUG(dbgs() << " STORE: " << *NewSI << "\n");
// If the store is volatile, add a check.
if (I.isVolatile())
@ -740,7 +740,7 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
insertCheck(Addr, &I);
if (ClTrackOrigins)
IRB.CreateStore(getOrigin(Val), getOriginPtr(Addr, IRB));
IRB.CreateAlignedStore(getOrigin(Val), getOriginPtr(Addr, IRB), I.getAlignment());
}
// Casts.

View File

@ -233,3 +233,28 @@ entry:
; CHECK: udiv
; CHECK-NOT: icmp
; CHECK: }
; Check that loads from shadow have the same aligment as the original loads.
define i32 @ShadowLoadAlignmentLarge() nounwind uwtable {
%y = alloca i32, align 64
%1 = load volatile i32* %y, align 64
ret i32 %1
}
; CHECK: define i32 @ShadowLoadAlignmentLarge
; CHECK: load i32* {{.*}} align 64
; CHECK: load volatile i32* {{.*}} align 64
; CHECK: }
define i32 @ShadowLoadAlignmentSmall() nounwind uwtable {
%y = alloca i32, align 2
%1 = load volatile i32* %y, align 2
ret i32 %1
}
; CHECK: define i32 @ShadowLoadAlignmentSmall
; CHECK: load i32* {{.*}} align 2
; CHECK: load volatile i32* {{.*}} align 2
; CHECK: }