[clang] [HLSL] Add matrix constructors using initalizer lists (PR #162743)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 20 15:50:47 PDT 2025
================
@@ -1877,6 +1887,41 @@ void InitListChecker::CheckReferenceType(const InitializedEntity &Entity,
AggrDeductionCandidateParamTypes->push_back(DeclType);
}
+void InitListChecker::CheckMatrixType(const InitializedEntity &Entity,
+ InitListExpr *IList, QualType DeclType,
+ unsigned &Index,
+ InitListExpr *StructuredList,
+ unsigned &StructuredIndex) {
+ if (!SemaRef.getLangOpts().HLSL)
+ return;
+
+ const ConstantMatrixType *MT = DeclType->castAs<ConstantMatrixType>();
+ QualType ElemTy = MT->getElementType();
+ const unsigned MaxElts = MT->getNumElementsFlattened();
+
+ unsigned NumEltsInit = 0;
+ InitializedEntity ElemEnt =
+ InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
+
+ while (NumEltsInit < MaxElts && Index < IList->getNumInits()) {
+ // Not a sublist: just consume directly.
+ ElemEnt.setElementIndex(Index);
+ CheckSubElementType(ElemEnt, IList, ElemTy, Index, StructuredList,
+ StructuredIndex);
+ ++NumEltsInit;
+ }
----------------
llvm-beanz wrote:
I looked at this and I understand what is going on. We need the code up to here. We'll never get this far if we have the wrong number of initializers because this happens after initializer flattening. We should add an assert `assert(NumEltsInit != MaxElts)`, and drop the rest of the function because that's unreachable.
https://github.com/llvm/llvm-project/pull/162743
More information about the cfe-commits
mailing list