[clang codegen] Clean up handling of vectors with trivial-auto-var-init.
The code was pretending to be doing something useful with vectors, but
really it was doing nothing: the element type of a vector is always a
scalar type, so constWithPadding would always just return the input constant.
Split off from D75661 so it can be reviewed separately.
While I'm here, also add testcase to show missing vector handling.
Differential Revision: https://reviews.llvm.org/D76528
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index c5de1e0..a6417f0 100644
--- 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<llvm::StructType>(OrigTy))
return constStructWithPadding(CGM, isPattern, STy, constant);
- if (auto *STy = dyn_cast<llvm::SequentialType>(OrigTy)) {
+ if (auto *ArrayTy = dyn_cast<llvm::ArrayType>(OrigTy)) {
llvm::SmallVector<llvm::Constant *, 8> 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;
}