forked from OSchip/llvm-project
IR: Make ConstantDataArray::getFP actually return a ConstantDataArray
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. llvm-svn: 255157
This commit is contained in:
parent
db51357c11
commit
b7389d6714
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue