Skip to content

Commit a09e070

Browse files
committed
address pr comment, CheckMatrixType doesn't need to handle non scalar types, because initalizer lists already do that for us
1 parent 9a57716 commit a09e070

File tree

1 file changed

+6
-58
lines changed

1 file changed

+6
-58
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,73 +1897,21 @@ void InitListChecker::CheckMatrixType(const InitializedEntity &Entity,
18971897

18981898
const ConstantMatrixType *MT = DeclType->castAs<ConstantMatrixType>();
18991899
QualType ElemTy = MT->getElementType();
1900-
const unsigned Rows = MT->getNumRows();
1901-
const unsigned Cols = MT->getNumColumns();
1902-
const unsigned MaxElts = Rows * Cols;
1900+
const unsigned MaxElts = MT->getNumElementsFlattened();
19031901

19041902
unsigned NumEltsInit = 0;
19051903
InitializedEntity ElemEnt =
19061904
InitializedEntity::InitializeElement(SemaRef.Context, 0, Entity);
19071905

1908-
// A Matrix initalizer should be able to take scalars, vectors, and matrices.
1909-
auto HandleInit = [&](InitListExpr *List, unsigned &Idx) {
1910-
Expr *Init = List->getInit(Idx);
1911-
QualType ITy = Init->getType();
1912-
1913-
if (ITy->isVectorType()) {
1914-
const VectorType *IVT = ITy->castAs<VectorType>();
1915-
unsigned N = IVT->getNumElements();
1916-
QualType VTy =
1917-
ITy->isExtVectorType()
1918-
? SemaRef.Context.getExtVectorType(ElemTy, N)
1919-
: SemaRef.Context.getVectorType(ElemTy, N, IVT->getVectorKind());
1920-
ElemEnt.setElementIndex(Idx);
1921-
CheckSubElementType(ElemEnt, List, VTy, Idx, StructuredList,
1922-
StructuredIndex);
1923-
NumEltsInit += N;
1924-
return;
1925-
}
1926-
1927-
if (ITy->isMatrixType()) {
1928-
const ConstantMatrixType *IMT = ITy->castAs<ConstantMatrixType>();
1929-
unsigned N = IMT->getNumRows() * IMT->getNumColumns();
1930-
QualType MTy = SemaRef.Context.getConstantMatrixType(
1931-
ElemTy, IMT->getNumRows(), IMT->getNumColumns());
1932-
ElemEnt.setElementIndex(Idx);
1933-
CheckSubElementType(ElemEnt, List, MTy, Idx, StructuredList,
1934-
StructuredIndex);
1935-
NumEltsInit += N;
1936-
return;
1937-
}
1938-
1939-
// Scalar element
1940-
ElemEnt.setElementIndex(Idx);
1941-
CheckSubElementType(ElemEnt, List, ElemTy, Idx, StructuredList,
1942-
StructuredIndex);
1943-
++NumEltsInit;
1944-
};
1945-
1946-
// Column-major: each top-level sublist is treated as a column.
19471906
while (NumEltsInit < MaxElts && Index < IList->getNumInits()) {
1948-
Expr *Init = IList->getInit(Index);
1949-
1950-
if (auto *SubList = dyn_cast<InitListExpr>(Init)) {
1951-
unsigned SubIdx = 0;
1952-
unsigned Row = 0;
1953-
while (Row < Rows && SubIdx < SubList->getNumInits() &&
1954-
NumEltsInit < MaxElts) {
1955-
HandleInit(SubList, SubIdx);
1956-
++Row;
1957-
}
1958-
++Index; // advance past this column sublist
1959-
continue;
1960-
}
1961-
19621907
// Not a sublist: just consume directly.
1963-
HandleInit(IList, Index);
1908+
ElemEnt.setElementIndex(Index);
1909+
CheckSubElementType(ElemEnt, IList, ElemTy, Index, StructuredList,
1910+
StructuredIndex);
1911+
++NumEltsInit;
19641912
}
19651913

1966-
// HLSL requires exactly Rows*Cols initializers after flattening.
1914+
// HLSL requires exactly NumEltsInit to equal Max initializers.
19671915
if (NumEltsInit != MaxElts) {
19681916
if (!VerifyOnly)
19691917
SemaRef.Diag(IList->getBeginLoc(),

0 commit comments

Comments
 (0)