Skip to content

Commit e213af7

Browse files
[MLIR][Presburger] Fix a bug with determinant of IntMatrix (#76622)
Fixed a bug where IntMatrix determinant() had a bug where it would try to assign to a null pointer. Added a test case that triggers this bug to avoid regressions.
1 parent 4b14205 commit e213af7

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

mlir/lib/Analysis/Presburger/Matrix.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ MPInt IntMatrix::determinant(IntMatrix *inverse) const {
452452
if (detM == 0)
453453
return MPInt(0);
454454

455+
if (!inverse)
456+
return detM;
457+
455458
*inverse = IntMatrix(nRows, nColumns);
456459
for (unsigned i = 0; i < nRows; i++)
457460
for (unsigned j = 0; j < nColumns; j++)

mlir/unittests/Analysis/Presburger/MatrixTest.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ TEST(MatrixTest, computeHermiteNormalForm) {
251251
}
252252

253253
TEST(MatrixTest, inverse) {
254+
IntMatrix mat1 = makeIntMatrix(2, 2, {{2, 1}, {7, 0}});
255+
EXPECT_EQ(mat1.determinant(), -7);
256+
254257
FracMatrix mat = makeFracMatrix(
255258
2, 2, {{Fraction(2), Fraction(1)}, {Fraction(7), Fraction(0)}});
256259
FracMatrix inverse = makeFracMatrix(

0 commit comments

Comments
 (0)