aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorShuxin Yang <shuxin.llvm@gmail.com>2013-06-08 04:56:05 +0000
committerShuxin Yang <shuxin.llvm@gmail.com>2013-06-08 04:56:05 +0000
commit9792b646c68d0dcee4049662091f1496b4c85ce7 (patch)
tree3770a7ba7fe041ccb747d7ae33b4870ede6614d7 /lib
parentdbfb960e74cc37e7a066f7fbcf78e6936a9e7794 (diff)
downloadexternal_llvm-9792b646c68d0dcee4049662091f1496b4c85ce7.zip
external_llvm-9792b646c68d0dcee4049662091f1496b4c85ce7.tar.gz
external_llvm-9792b646c68d0dcee4049662091f1496b4c85ce7.tar.bz2
Fix a potential bug in r183584.
r183584 tries to derive some info from the code *AFTER* a call and apply these derived info to the code *BEFORE* the call, which is not always safe as the call in question may never return, and in this case, the derived info is invalid. Thank Duncan for pointing out this potential bug. rdar://14073661 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183606 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/MemCpyOptimizer.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 8600c9e..c325925 100644
--- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -626,10 +626,14 @@ bool MemCpyOpt::performCallSlotOptzn(Instruction *cpy,
return false;
Type *StructTy = cast<PointerType>(A->getType())->getElementType();
- // If StructTy is an opaque type, it should have at least <cpyLen> bytes,
- // as implified by the copy-instruction.
- uint64_t destSize = StructTy->isSized() ?
- TD->getTypeAllocSize(StructTy) : cpyLen;
+ if (!StructTy->isSized()) {
+ // The call may never return and hence the copy-instruction may never
+ // be executed, and therefore it's not safe to say "the destination
+ // has at least <cpyLen> bytes, as implied by the copy-instruction",
+ return false;
+ }
+
+ uint64_t destSize = TD->getTypeAllocSize(StructTy);
if (destSize < srcSize)
return false;
} else {