From: Justin Bogner Date: Wed, 9 Dec 2015 21:21:07 +0000 (+0000) Subject: IR: Make ConstantDataArray::getFP actually return a ConstantDataArray X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4381284cf88991a0971886daa914225539c570e5;p=oota-llvm.git IR: Make ConstantDataArray::getFP actually return a ConstantDataArray The ConstantDataArray::getFP(LLVMContext &, ArrayRef) 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 --- diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp index 509783fff8b..36282c16429 100644 --- a/lib/IR/Constants.cpp +++ b/lib/IR/Constants.cpp @@ -2523,7 +2523,7 @@ Constant *ConstantDataArray::get(LLVMContext &Context, ArrayRef Elts) { /// object. Constant *ConstantDataArray::getFP(LLVMContext &Context, ArrayRef Elts) { - Type *Ty = VectorType::get(Type::getHalfTy(Context), Elts.size()); + Type *Ty = ArrayType::get(Type::getHalfTy(Context), Elts.size()); const char *Data = reinterpret_cast(Elts.data()); return getImpl(StringRef(const_cast(Data), Elts.size() * 2), Ty); } diff --git a/test/Transforms/ConstProp/insertvalue.ll b/test/Transforms/ConstProp/insertvalue.ll index dce2b728b93..606f7ddc679 100644 --- a/test/Transforms/ConstProp/insertvalue.ll +++ b/test/Transforms/ConstProp/insertvalue.ll @@ -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 +} diff --git a/unittests/IR/ConstantsTest.cpp b/unittests/IR/ConstantsTest.cpp index 8c33453d293..0bf98f35b3c 100644 --- a/unittests/IR/ConstantsTest.cpp +++ b/unittests/IR/ConstantsTest.cpp @@ -389,6 +389,29 @@ static std::string getNameOfType(Type *T) { return S; } +TEST(ConstantsTest, BuildConstantDataArrays) { + LLVMContext Context; + std::unique_ptr 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(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(CDV) != nullptr) + << " T = " << getNameOfType(T); + } +} + TEST(ConstantsTest, BuildConstantDataVectors) { LLVMContext Context; std::unique_ptr M(new Module("MyModule", Context));