[ConstantFold] Fix bitcast to gep constant folding transform.
[oota-llvm.git] / unittests / IR / ConstantsTest.cpp
index 0bf98f35b3c8148150635e776bc8793d0d3ced5d..e3b303a350db7317c611ba9beba907a942d4e04f 100644 (file)
@@ -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
 }  // end anonymous namespace
 }  // end namespace llvm