In my recent change to avoid use of underaligned memory I didn't notice that

cpyDest can be mutated in some cases, which would then cause a crash later if
indeed the memory was underaligned.  This brought down several buildbots, so
I guess the underaligned case is much more common than I thought!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165228 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands 2012-10-04 13:53:21 +00:00
parent ffcf6dffee
commit 7508f946bc
2 changed files with 9 additions and 9 deletions

View File

@ -692,15 +692,15 @@ bool MemCpyOpt::performCallSlotOptzn(Instruction *cpy,
bool changedArgument = false; bool changedArgument = false;
for (unsigned i = 0; i < CS.arg_size(); ++i) for (unsigned i = 0; i < CS.arg_size(); ++i)
if (CS.getArgument(i)->stripPointerCasts() == cpySrc) { if (CS.getArgument(i)->stripPointerCasts() == cpySrc) {
if (cpySrc->getType() != cpyDest->getType()) Value *Dest = cpySrc->getType() == cpyDest->getType() ? cpyDest
cpyDest = CastInst::CreatePointerCast(cpyDest, cpySrc->getType(), : CastInst::CreatePointerCast(cpyDest, cpySrc->getType(),
cpyDest->getName(), C); cpyDest->getName(), C);
changedArgument = true; changedArgument = true;
if (CS.getArgument(i)->getType() == cpyDest->getType()) if (CS.getArgument(i)->getType() == Dest->getType())
CS.setArgument(i, cpyDest); CS.setArgument(i, Dest);
else else
CS.setArgument(i, CastInst::CreatePointerCast(cpyDest, CS.setArgument(i, CastInst::CreatePointerCast(Dest,
CS.getArgument(i)->getType(), cpyDest->getName(), C)); CS.getArgument(i)->getType(), Dest->getName(), C));
} }
if (!changedArgument) if (!changedArgument)

View File

@ -9,11 +9,11 @@ declare void @g(%a*)
define float @f() { define float @f() {
entry: entry:
%a_var = alloca %a %a_var = alloca %a
%b_var = alloca %b %b_var = alloca %b, align 1
call void @g(%a* %a_var) call void @g(%a* %a_var)
%a_i8 = bitcast %a* %a_var to i8* %a_i8 = bitcast %a* %a_var to i8*
%b_i8 = bitcast %b* %b_var to i8* %b_i8 = bitcast %b* %b_var to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b_i8, i8* %a_i8, i32 4, i32 4, i1 false) call void @llvm.memcpy.p0i8.p0i8.i32(i8* %b_i8, i8* %a_i8, i32 4, i32 1, i1 false)
%tmp1 = getelementptr %b* %b_var, i32 0, i32 0 %tmp1 = getelementptr %b* %b_var, i32 0, i32 0
%tmp2 = load float* %tmp1 %tmp2 = load float* %tmp1
ret float %tmp2 ret float %tmp2