IR: Make ConstantDataArray::getFP actually return a ConstantDataArray
[oota-llvm.git] / unittests / IR / ConstantsTest.cpp
index 8c33453d293dfb6432bf7fabaf7caf219a2c4bed..0bf98f35b3c8148150635e776bc8793d0d3ced5d 100644 (file)
@@ -389,6 +389,29 @@ static std::string getNameOfType(Type *T) {
   return S;
 }
 
+TEST(ConstantsTest, BuildConstantDataArrays) {
+  LLVMContext Context;
+  std::unique_ptr<Module> M(new Module("MyModule", Context));
+
+  for (Type *T : {Type::getInt8Ty(Context), Type::getInt16Ty(Context),
+                  Type::getInt32Ty(Context), Type::getInt64Ty(Context)}) {
+    ArrayType *ArrayTy = ArrayType::get(T, 2);
+    Constant *Vals[] = {ConstantInt::get(T, 0), ConstantInt::get(T, 1)};
+    Constant *CDV = ConstantArray::get(ArrayTy, Vals);
+    ASSERT_TRUE(dyn_cast<ConstantDataArray>(CDV) != nullptr)
+        << " T = " << getNameOfType(T);
+  }
+
+  for (Type *T : {Type::getHalfTy(Context), Type::getFloatTy(Context),
+                  Type::getDoubleTy(Context)}) {
+    ArrayType *ArrayTy = ArrayType::get(T, 2);
+    Constant *Vals[] = {ConstantFP::get(T, 0), ConstantFP::get(T, 1)};
+    Constant *CDV = ConstantArray::get(ArrayTy, Vals);
+    ASSERT_TRUE(dyn_cast<ConstantDataArray>(CDV) != nullptr)
+        << " T = " << getNameOfType(T);
+  }
+}
+
 TEST(ConstantsTest, BuildConstantDataVectors) {
   LLVMContext Context;
   std::unique_ptr<Module> M(new Module("MyModule", Context));