[ADT] Don't use a fixture just to get a nonce type for this unittest.
[oota-llvm.git] / unittests / IR / ConstantsTest.cpp
index 0bf98f35b3c8148150635e776bc8793d0d3ced5d..7471584097ddaa351571836e1d001e879c6ae849 100644 (file)
@@ -15,6 +15,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm-c/Core.h"
 #include "gtest/gtest.h"
 
 namespace llvm {
@@ -433,5 +434,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