Skip to content

Commit

Permalink
[MLIR][Presburger] Make constructors from PresburgerSpace explicit
Browse files Browse the repository at this point in the history
This patch makes constructors of IntegerRelation, IntegerPolyhedron,
PresburgerRelation, PresburgerSet from PresburgerSpace explicit. This
prevents bugs like:

```
void fun(IntegerRelation a, IntegerRelation b) {
  IntegerPolyhedron c = a.intersect(b);
}
```

Here, `a.intersect(b)` will return `IntegerRelation`, which will be implicitly
converted to `PresburgerSpace` and will use the `PresburgerSpace` constructor
for IntegerPolyhedron. Leading to loss of any constraints in the intersection
of `a` and `b`. After this patch, this will give a compile error.

Reviewed By: arjunp

Differential Revision: https://reviews.llvm.org/D122972
  • Loading branch information
Groverkss committed Apr 2, 2022
1 parent cc21395 commit 86f2553
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
Expand Up @@ -66,7 +66,7 @@ class IntegerRelation : public PresburgerSpace {
}

/// Constructs a relation with the specified number of dimensions and symbols.
IntegerRelation(const PresburgerSpace &space)
explicit IntegerRelation(const PresburgerSpace &space)
: IntegerRelation(/*numReservedInequalities=*/0,
/*numReservedEqualities=*/0,
/*numReservedCols=*/space.getNumIds() + 1, space) {}
Expand Down Expand Up @@ -567,7 +567,7 @@ class IntegerPolyhedron : public IntegerRelation {

/// Constructs a relation with the specified number of dimensions and
/// symbols.
IntegerPolyhedron(const PresburgerSpace &space)
explicit IntegerPolyhedron(const PresburgerSpace &space)
: IntegerPolyhedron(/*numReservedInequalities=*/0,
/*numReservedEqualities=*/0,
/*numReservedCols=*/space.getNumIds() + 1, space) {}
Expand Down
6 changes: 4 additions & 2 deletions mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
Expand Up @@ -116,7 +116,8 @@ class PresburgerRelation : public PresburgerSpace {
protected:
/// Construct an empty PresburgerRelation with the specified number of
/// dimension and symbols.
PresburgerRelation(const PresburgerSpace &space) : PresburgerSpace(space) {
explicit PresburgerRelation(const PresburgerSpace &space)
: PresburgerSpace(space) {
assert(space.getNumLocalIds() == 0 &&
"PresburgerRelation cannot have local ids.");
}
Expand Down Expand Up @@ -151,7 +152,8 @@ class PresburgerSet : public PresburgerRelation {
protected:
/// Construct an empty PresburgerRelation with the specified number of
/// dimension and symbols.
PresburgerSet(const PresburgerSpace &space) : PresburgerRelation(space) {
explicit PresburgerSet(const PresburgerSpace &space)
: PresburgerRelation(space) {
assert(space.getNumDomainIds() == 0 && "Set type cannot have domain ids.");
assert(space.getNumLocalIds() == 0 &&
"PresburgerRelation cannot have local ids.");
Expand Down

0 comments on commit 86f2553

Please sign in to comment.