[Mlir-commits] [mlir] 86f2553 - [MLIR][Presburger] Make constructors from PresburgerSpace explicit

llvmlistbot at llvm.org llvmlistbot at llvm.org
Sat Apr 2 06:01:37 PDT 2022


Author: Groverkss
Date: 2022-04-02T18:14:38+05:30
New Revision: 86f255360c4f1741e8c5bef95e6994b81cd8d2e1

URL: https://github.com/llvm/llvm-project/commit/86f255360c4f1741e8c5bef95e6994b81cd8d2e1
DIFF: https://github.com/llvm/llvm-project/commit/86f255360c4f1741e8c5bef95e6994b81cd8d2e1.diff

LOG: [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

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
    mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
index 47a1ae2ae656a..6add6e8aa9b24 100644
--- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
@@ -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) {}
@@ -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) {}

diff  --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
index bc64fbef44dbc..b0015fd1f03b4 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
@@ -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.");
   }
@@ -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.");


        


More information about the Mlir-commits mailing list