[MLIR][Presburger] Make constructors from PresburgerSpace explicit

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
This commit is contained in:
Groverkss 2022-04-02 18:14:38 +05:30
parent cc2139524f
commit 86f255360c
2 changed files with 6 additions and 4 deletions

View file

@ -66,7 +66,7 @@ public:
}
/// 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) {}
@ -567,7 +567,7 @@ public:
/// 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) {}

View file

@ -116,7 +116,8 @@ public:
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.");
}
@ -151,7 +152,8 @@ public:
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.");