Skip to content

Commit 75a2fd9

Browse files
committed
!fixup move extends to CG.
1 parent b68f638 commit 75a2fd9

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
@@ -4348,8 +4348,18 @@ LValue CodeGenFunction::EmitMatrixSubscriptExpr(const MatrixSubscriptExpr *E) {
43484348
!E->isIncomplete() &&
43494349
"incomplete matrix subscript expressions should be rejected during Sema");
43504350
LValue Base = EmitLValue(E->getBase());
4351-
llvm::Value *RowIdx = EmitScalarExpr(E->getRowIdx());
4352-
llvm::Value *ColIdx = EmitScalarExpr(E->getColumnIdx());
4351+
4352+
// Extend or truncate the index type to 32 or 64-bits.
4353+
auto EmitIndex = [this](const Expr *E) {
4354+
llvm::Value *Idx = EmitScalarExpr(E);
4355+
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
4356+
if (Idx->getType() != IntPtrTy)
4357+
Idx = Builder.CreateIntCast(Idx, IntPtrTy, IsSigned);
4358+
return Idx;
4359+
};
4360+
llvm::Value *RowIdx = EmitIndex(E->getRowIdx());
4361+
llvm::Value *ColIdx = EmitIndex(E->getColumnIdx());
4362+
43534363
llvm::Value *NumRows = Builder.getIntN(
43544364
RowIdx->getType()->getScalarSizeInBits(),
43554365
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
@@ -2007,8 +2007,15 @@ Value *ScalarExprEmitter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
20072007

20082008
// Handle the vector case. The base must be a vector, the index must be an
20092009
// integer value.
2010-
Value *RowIdx = Visit(E->getRowIdx());
2011-
Value *ColumnIdx = Visit(E->getColumnIdx());
2010+
auto VisitIndex = [this](Expr *E) {
2011+
llvm::Value *Idx = Visit(E);
2012+
bool IsSigned = E->getType()->isSignedIntegerOrEnumerationType();
2013+
if (Idx->getType() != CGF.IntPtrTy)
2014+
Idx = Builder.CreateIntCast(Idx, CGF.IntPtrTy, IsSigned);
2015+
return Idx;
2016+
};
2017+
Value *RowIdx = VisitIndex(E->getRowIdx());
2018+
Value *ColumnIdx = VisitIndex(E->getColumnIdx());
20122019

20132020
const auto *MatrixTy = E->getBase()->getType()->castAs<ConstantMatrixType>();
20142021
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)