Skip to content

Commit ec5f18e

Browse files
committed
[MLIR][Presburger] MPInt: gcd: assert that operands are non-negative
1 parent 2315358 commit ec5f18e

File tree

1 file changed

+2
-0
lines changed
  • mlir/include/mlir/Analysis/Presburger

1 file changed

+2
-0
lines changed

mlir/include/mlir/Analysis/Presburger/MPInt.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ class MPInt {
195195
friend MPInt gcdRange(ArrayRef<MPInt> range);
196196
friend MPInt ceilDiv(const MPInt &lhs, const MPInt &rhs);
197197
friend MPInt floorDiv(const MPInt &lhs, const MPInt &rhs);
198+
// The operands must be non-negative for gcd.
198199
friend MPInt gcd(const MPInt &a, const MPInt &b);
199200
friend MPInt lcm(const MPInt &a, const MPInt &b);
200201
friend MPInt mod(const MPInt &lhs, const MPInt &rhs);
@@ -382,6 +383,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mod(const MPInt &lhs, const MPInt &rhs) {
382383
}
383384

384385
LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt gcd(const MPInt &a, const MPInt &b) {
386+
assert(a >= 0 && b >= 0 && "operands must be non-negative!");
385387
if (LLVM_LIKELY(a.isSmall() && b.isSmall()))
386388
return MPInt(llvm::greatestCommonDivisor(a.getSmall(), b.getSmall()));
387389
return MPInt(gcd(detail::SlowMPInt(a), detail::SlowMPInt(b)));

0 commit comments

Comments
 (0)