@@ -2134,26 +2134,29 @@ void InitListChecker::CheckMatrixType(const InitializedEntity &Entity,
21342134 return ;
21352135
21362136 const ConstantMatrixType *MT = DeclType->castAs <ConstantMatrixType>();
2137+
2138+ // For HLSL, the error reporting for this case is handled in SemaHLSL's
2139+ // initializer list diagnostics. That means the execution should require
2140+ // getNumElementsFlattened to equal getNumInits. In other words the execution
2141+ // should never reach this point if this condition is not true".
2142+ assert (IList->getNumInits () == MT->getNumElementsFlattened () &&
2143+ " Inits must equal Matrix element count" );
2144+
21372145 QualType ElemTy = MT->getElementType ();
2138- const unsigned MaxElts = MT->getNumElementsFlattened ();
21392146
2140- unsigned NumEltsInit = 0 ;
2147+ Index = 0 ;
21412148 InitializedEntity ElemEnt =
21422149 InitializedEntity::InitializeElement (SemaRef.Context , 0 , Entity);
21432150
2144- while (NumEltsInit < MaxElts && Index < IList->getNumInits ()) {
2151+ while (Index < IList->getNumInits ()) {
21452152 // Not a sublist: just consume directly.
2146- ElemEnt.setElementIndex (Index);
2147- CheckSubElementType (ElemEnt, IList, ElemTy, Index, StructuredList,
2153+ unsigned ColMajorIndex = (Index % MT->getNumRows ()) * MT->getNumColumns () +
2154+ (Index / MT->getNumRows ());
2155+ ElemEnt.setElementIndex (ColMajorIndex);
2156+ CheckSubElementType (ElemEnt, IList, ElemTy, ColMajorIndex, StructuredList,
21482157 StructuredIndex);
2149- ++NumEltsInit ;
2158+ ++Index ;
21502159 }
2151-
2152- // For HLSL The error for this case is handled in SemaHLSL's initializer
2153- // list diagnostics, That means the execution should require NumEltsInit
2154- // to equal Max initializers. In other words execution should never
2155- // reach this point if this condition is not true".
2156- assert (NumEltsInit == MaxElts && " NumEltsInit must equal MaxElts" );
21572160}
21582161
21592162void InitListChecker::CheckVectorType (const InitializedEntity &Entity,
0 commit comments