From 86f255360c4f1741e8c5bef95e6994b81cd8d2e1 Mon Sep 17 00:00:00 2001 From: Groverkss Date: Sat, 2 Apr 2022 18:14:38 +0530 Subject: [PATCH] [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 --- mlir/include/mlir/Analysis/Presburger/IntegerRelation.h | 4 ++-- mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h index 47a1ae2ae656..6add6e8aa9b2 100644 --- a/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/IntegerRelation.h @@ -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) {} diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h index bc64fbef44db..b0015fd1f03b 100644 --- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h @@ -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.");