summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
diff options
context:
space:
mode:
authorGerolf Hoflehner <ghoflehner@apple.com>2016-05-23 19:23:17 +0000
committerGerolf Hoflehner <ghoflehner@apple.com>2016-05-23 19:23:17 +0000
commit00e7092f68fe462b7a1dbcf424f66de60180f687 (patch)
tree0eb230f840516ee33909fb1397caa5286cd57e89 /llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
parentbe080fc51d77b80f82fe7d220815a29a7b89dea1 (diff)
downloadbcm5719-llvm-00e7092f68fe462b7a1dbcf424f66de60180f687.tar.gz
bcm5719-llvm-00e7092f68fe462b7a1dbcf424f66de60180f687.zip
[InstCombine] Fix assertion when bitcast is converted to gep
When an aggregate contains an opaque type its size cannot be determined. This triggers an "Invalid GetElementPtrInst indices for type" assert in function checkGEPType. The fix suppresses the conversion in this case. http://reviews.llvm.org/D20319 llvm-svn: 270479
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 80b138e8c36..dddcd0183b3 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1922,6 +1922,13 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
if (Instruction *V = PromoteCastOfAllocation(CI, *AI))
return V;
+ // When the type pointed to is not sized the cast cannot be
+ // turned into a gep.
+ Type *PointeeType =
+ cast<PointerType>(Src->getType()->getScalarType())->getElementType();
+ if (!PointeeType->isSized())
+ return nullptr;
+
// If the source and destination are pointers, and this cast is equivalent
// to a getelementptr X, 0, 0, 0... turn it into the appropriate gep.
// This can enhance SROA and other transforms that want type-safe pointers.
OpenPOWER on IntegriCloud