diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -1050,13 +1050,13 @@ llvm::Type *OrigTy = constant->getType(); if (const auto STy = dyn_cast(OrigTy)) return constStructWithPadding(CGM, isPattern, STy, constant); - if (auto *STy = dyn_cast(OrigTy)) { + if (auto *ArrayTy = dyn_cast(OrigTy)) { llvm::SmallVector Values; - unsigned Size = STy->getNumElements(); + uint64_t Size = ArrayTy->getNumElements(); if (!Size) return constant; - llvm::Type *ElemTy = STy->getElementType(); - bool ZeroInitializer = constant->isZeroValue(); + llvm::Type *ElemTy = ArrayTy->getElementType(); + bool ZeroInitializer = constant->isNullValue(); llvm::Constant *OpValue, *PaddedOp; if (ZeroInitializer) { OpValue = llvm::Constant::getNullValue(ElemTy); @@ -1072,13 +1072,10 @@ auto *NewElemTy = Values[0]->getType(); if (NewElemTy == ElemTy) return constant; - if (OrigTy->isArrayTy()) { - auto *ArrayTy = llvm::ArrayType::get(NewElemTy, Size); - return llvm::ConstantArray::get(ArrayTy, Values); - } else { - return llvm::ConstantVector::get(Values); - } + auto *NewArrayTy = llvm::ArrayType::get(NewElemTy, Size); + return llvm::ConstantArray::get(NewArrayTy, Values); } + // FIXME: Do we need to handle tail padding in vectors? return constant; } diff --git a/clang/test/CodeGenCXX/auto-var-init.cpp b/clang/test/CodeGenCXX/auto-var-init.cpp --- a/clang/test/CodeGenCXX/auto-var-init.cpp +++ b/clang/test/CodeGenCXX/auto-var-init.cpp @@ -1610,5 +1610,24 @@ // CHECK-NEXT: store <4 x double> , <4 x double>* %custom, align [[ALIGN]] // CHECK-NEXT: call void @{{.*}}used{{.*}}%custom) +// TODO: This vector has tail padding +TEST_UNINIT(doublevec24, double __attribute__((vector_size(24)))); +// CHECK-LABEL: @test_doublevec24_uninit() +// CHECK: %uninit = alloca <3 x double>, align +// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit) +// PATTERN-LABEL: @test_doublevec24_uninit() +// PATTERN: store <3 x double> , <3 x double>* %uninit, align 32 +// ZERO-LABEL: @test_doublevec24_uninit() +// ZERO: store <3 x double> zeroinitializer, <3 x double>* %uninit, align 32 + +// TODO: This vector has tail padding +TEST_UNINIT(longdoublevec32, long double __attribute__((vector_size(sizeof(long double)*2)))); +// CHECK-LABEL: @test_longdoublevec32_uninit() +// CHECK: %uninit = alloca <2 x x86_fp80>, align +// CHECK-NEXT: call void @{{.*}}used{{.*}}%uninit) +// PATTERN-LABEL: @test_longdoublevec32_uninit() +// PATTERN: store <2 x x86_fp80> , <2 x x86_fp80>* %uninit, align 32 +// ZERO-LABEL: @test_longdoublevec32_uninit() +// ZERO: store <2 x x86_fp80> zeroinitializer, <2 x x86_fp80>* %uninit, align 32 } // extern "C"