IR: Make ConstantDataArray::getFP actually return a ConstantDataArray
authorJustin Bogner <mail@justinbogner.com>
Wed, 9 Dec 2015 21:21:07 +0000 (21:21 +0000)
committerJustin Bogner <mail@justinbogner.com>
Wed, 9 Dec 2015 21:21:07 +0000 (21:21 +0000)
The ConstantDataArray::getFP(LLVMContext &, ArrayRef<uint16_t>)
overload has had a typo in it since it was written, where it will
create a Vector instead of an Array. This obviously doesn't work at
all, but it turns out that until r254991 there weren't actually any
callers of this overload. Fix the typo and add some test coverage.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255157 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/Constants.cpp
test/Transforms/ConstProp/insertvalue.ll
unittests/IR/ConstantsTest.cpp

index 509783fff8bdf8f404d07fe9e5809df944121bea..36282c164293f727352df1954ff467524ce1b202 100644 (file)
@@ -2523,7 +2523,7 @@ Constant *ConstantDataArray::get(LLVMContext &Context, ArrayRef<double> Elts) {
 /// object.
 Constant *ConstantDataArray::getFP(LLVMContext &Context,
                                    ArrayRef<uint16_t> Elts) {
-  Type *Ty = VectorType::get(Type::getHalfTy(Context), Elts.size());
+  Type *Ty = ArrayType::get(Type::getHalfTy(Context), Elts.size());
   const char *Data = reinterpret_cast<const char *>(Elts.data());
   return getImpl(StringRef(const_cast<char *>(Data), Elts.size() * 2), Ty);
 }
index dce2b728b93b0fff9719a769cdd068dbfe8a096e..606f7ddc679cd1a4fd9f29b3a13618520727f948 100644 (file)
@@ -74,3 +74,13 @@ define i32 @test-float-Nan() {
 ; CHECK: @test-float-Nan
 ; CHECK: ret i32 2139171423
 }
+
+define i16 @test-half-Nan() {
+  %A = bitcast i16 32256 to half
+  %B = insertvalue [1 x half] undef, half %A, 0
+  %C = extractvalue [1 x half] %B, 0
+  %D = bitcast half %C to i16
+  ret i16 %D
+; CHECK: @test-half-Nan
+; CHECK: ret i16 32256
+}
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));