================
@@ -2081,6 +2081,56 @@ void CGDebugInfo::CollectRecordLambdaFields(
}
}
+/// Build an llvm::ConstantDataArray from the initialized elements of an
+/// APValue array, using the narrowest integer type that fits the element
width.
+template <typename T, unsigned InlineN = 64>
+static llvm::Constant *
+buildConstantDataArrayFromElements(llvm::LLVMContext &Ctx, const APValue &Arr)
{
+ const unsigned NumElts = Arr.getArraySize();
+ SmallVector<T, InlineN> Vals(
+ NumElts,
+ Arr.hasArrayFiller()
+ ? static_cast<T>(Arr.getArrayFiller().getInt().getZExtValue())
+ : 0);
+ for (unsigned I : llvm::seq(Arr.getArrayInitializedElts()))
+ Vals[I] =
+ static_cast<T>(Arr.getArrayInitializedElt(I).getInt().getZExtValue());
+ return llvm::ConstantDataArray::get(Ctx, Vals);
+}
+
+/// Try to create an llvm::Constant for a constexpr array of integer elements.
+/// Handles arrays of char, short, int, long with element width up to 64 bits.
+/// Returns nullptr if the array cannot be represented.
+static llvm::Constant *tryEmitConstexprArrayAsConstant(CodeGenModule &CGM,
+ const VarDecl *Var,
+ const APValue *Value) {
+ const auto *ArrayTy =
CGM.getContext().getAsConstantArrayType(Var->getType());
+ if (!ArrayTy)
+ return nullptr;
+
+ const QualType ElemQTy = ArrayTy->getElementType();
+ if (ElemQTy.isNull() || !ElemQTy->isIntegerType())
+ return nullptr;
+
+ const unsigned ElemBitWidth = CGM.getContext().getTypeSize(ElemQTy);
----------------
Michael137 wrote:
```suggestion
const uint64_t ElemBitWidth = CGM.getContext().getTypeSize(ElemQTy);
```
Or just put this call into the `switch(...)`
https://github.com/llvm/llvm-project/pull/182442
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits