summaryrefslogtreecommitdiffstats
path: root/llvm/unittests
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2015-12-14 19:30:32 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2015-12-14 19:30:32 +0000
commit59be1d653ae63bcb0146151a70513ca39e241647 (patch)
tree7a7fd90a51b578dc054cdea4b8563b9daef897bc /llvm/unittests
parent45ea8fa1f423a9d44be1152263eec986ca5773ee (diff)
downloadbcm5719-llvm-59be1d653ae63bcb0146151a70513ca39e241647.tar.gz
bcm5719-llvm-59be1d653ae63bcb0146151a70513ca39e241647.zip
[ConstantFold] Fix bitcast to gep constant folding transform.
Make sure to check that the destination type is sized. A check was present but was incorrectly checking the source type instead. Patch by Amaury SECHET! Differential Revision: http://reviews.llvm.org/D15264 llvm-svn: 255536
Diffstat (limited to 'llvm/unittests')
-rw-r--r--llvm/unittests/IR/ConstantsTest.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/unittests/IR/ConstantsTest.cpp b/llvm/unittests/IR/ConstantsTest.cpp
index 0bf98f35b3c..e3b303a350d 100644
--- a/llvm/unittests/IR/ConstantsTest.cpp
+++ b/llvm/unittests/IR/ConstantsTest.cpp
@@ -433,5 +433,22 @@ TEST(ConstantsTest, BuildConstantDataVectors) {
}
}
+TEST(ConstantsTest, BitcastToGEP) {
+ LLVMContext Context;
+ std::unique_ptr<Module> M(new Module("MyModule", Context));
+
+ auto *i32 = Type::getInt32Ty(Context);
+ auto *U = StructType::create(Context, "Unsized");
+ Type *EltTys[] = {i32, U};
+ auto *S = StructType::create(EltTys);
+
+ auto *G = new GlobalVariable(*M, S, false,
+ GlobalValue::ExternalLinkage, nullptr);
+ auto *PtrTy = PointerType::get(i32, 0);
+ auto *C = ConstantExpr::getBitCast(G, PtrTy);
+ ASSERT_EQ(dyn_cast<ConstantExpr>(C)->getOpcode(),
+ Instruction::BitCast);
+}
+
} // end anonymous namespace
} // end namespace llvm
OpenPOWER on IntegriCloud