Skip to content

Commit 4efcce8

Browse files
committed
!fixup move extends to CG.
1 parent 3fc9632 commit 4efcce8

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4397,8 +4397,18 @@ LValue CodeGenFunction::EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E) {
43974397
!E->isIncomplete() &&
43984398
"incomplete matrix subscript expressions should be rejected during Sema");
43994399
LValue Base = EmitLValue(E->getBase());
4400-
llvm::Value *RowIdx = EmitScalarExpr(E->getRowIdx());
4401-
llvm::Value *ColIdx = EmitScalarExpr(E->getColumnIdx());
4400+
4401+
// Extend or truncate the index type to 32 or 64-bits.
4402+
auto EmitIndex = [this](const Expr *E) {
4403+
llvm::Value *Idx = EmitScalarExpr(E);
4404+
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
4405+
if (Idx->getType() != IntPtrTy)
4406+
Idx = Builder.CreateIntCast(Idx, IntPtrTy, IsSigned);
4407+
return Idx;
4408+
};
4409+
llvm::Value *RowIdx = EmitIndex(E->getRowIdx());
4410+
llvm::Value *ColIdx = EmitIndex(E->getColumnIdx());
4411+
44024412
llvm::Value *NumRows = Builder.getIntN(
44034413
RowIdx->getType()->getScalarSizeInBits(),
44044414
E->getBase()->getType()->castAs<ConstantMatrixType>()->getNumRows());

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,8 +1995,15 @@ Value *ScalarExprEmitter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
19951995

19961996
// Handle the vector case. The base must be a vector, the index must be an
19971997
// integer value.
1998-
Value *RowIdx = Visit(E->getRowIdx());
1999-
Value *ColumnIdx = Visit(E->getColumnIdx());
1998+
auto VisitIndex = [this](Expr *E) {
1999+
llvm::Value *Idx = Visit(E);
2000+
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
2001+
if (Idx->getType() != CGF.IntPtrTy)
2002+
Idx = Builder.CreateIntCast(Idx, CGF.IntPtrTy, IsSigned);
2003+
return Idx;
2004+
};
2005+
Value *RowIdx = VisitIndex(E->getRowIdx());
2006+
Value *ColumnIdx = VisitIndex(E->getColumnIdx());
20002007

20012008
const auto *MatrixTy = E->getBase()->getType()->castAs<ConstantMatrixType>();
20022009
unsigned NumRows = MatrixTy->getNumRows();

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5025,10 +5025,7 @@ ExprResult Sema::CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx,
50255025
}
50265026
}
50275027

5028-
ExprResult ConvExpr = tryConvertExprToType(
5029-
IndexExpr, IndexExpr->getType()->isSignedIntegerType()
5030-
? Context.getSignedSizeType()
5031-
: Context.getSizeType());
5028+
ExprResult ConvExpr = IndexExpr;
50325029
assert(!ConvExpr.isInvalid() &&
50335030
"should be able to convert any integer type to size type");
50345031
return ConvExpr.get();

0 commit comments

Comments
 (0)