[PATCH] D80497: Make mlir::Value's bool conversion operator explicit

Benjamin Kramer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 24 14:24:07 PDT 2020


bkramer created this revision.
bkramer added reviewers: mehdi_amini, rriddle.
Herald added subscribers: llvm-commits, jurahul, Kayjukh, frgossen, grosul1, Joonsoo, stephenneuendorffer, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar.
Herald added 1 blocking reviewer(s): rriddle.
Herald added a reviewer: aartbik.
Herald added a project: LLVM.
bkramer updated this revision to Diff 265944.
bkramer added a comment.

Put back sort


This still allows `if (value)` while requiring an explicit cast when not
in a boolean context. This means things like `std::set<Value>` will no
longer compile.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80497

Files:
  mlir/include/mlir/EDSC/Builders.h
  mlir/include/mlir/IR/Value.h
  mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
  mlir/lib/Parser/Parser.cpp


Index: mlir/lib/Parser/Parser.cpp
===================================================================
--- mlir/lib/Parser/Parser.cpp
+++ mlir/lib/Parser/Parser.cpp
@@ -3542,14 +3542,14 @@
   // Check for any forward references that are left.  If we find any, error
   // out.
   if (!forwardRefPlaceholders.empty()) {
-    SmallVector<std::pair<const char *, Value>, 4> errors;
+    SmallVector<const char *, 4> errors;
     // Iteration over the map isn't deterministic, so sort by source location.
     for (auto entry : forwardRefPlaceholders)
-      errors.push_back({entry.second.getPointer(), entry.first});
+      errors.push_back(entry.second.getPointer());
     llvm::array_pod_sort(errors.begin(), errors.end());
 
     for (auto entry : errors) {
-      auto loc = SMLoc::getFromPointer(entry.first);
+      auto loc = SMLoc::getFromPointer(entry);
       emitError(loc, "use of undeclared SSA value name");
     }
     return failure();
Index: mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
===================================================================
--- mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
+++ mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
@@ -281,7 +281,8 @@
     }
   });
 
-  assert((!options.unroll ^ result) && "Expected resulting Value iff unroll");
+  assert((!options.unroll ^ (bool)result) &&
+         "Expected resulting Value iff unroll");
   if (!result)
     result = std_load(vector_type_cast(MemRefType::get({}, vectorType), alloc));
   rewriter.replaceOp(op, result);
Index: mlir/include/mlir/IR/Value.h
===================================================================
--- mlir/include/mlir/IR/Value.h
+++ mlir/include/mlir/IR/Value.h
@@ -92,7 +92,7 @@
     return U(ownerAndKind);
   }
 
-  operator bool() const { return ownerAndKind.getPointer(); }
+  explicit operator bool() const { return ownerAndKind.getPointer(); }
   bool operator==(const Value &other) const {
     return ownerAndKind == other.ownerAndKind;
   }
Index: mlir/include/mlir/EDSC/Builders.h
===================================================================
--- mlir/include/mlir/EDSC/Builders.h
+++ mlir/include/mlir/EDSC/Builders.h
@@ -303,7 +303,7 @@
            "MemRef, RankedTensor or Vector expected");
   }
 
-  bool hasValue() const { return value; }
+  bool hasValue() const { return (bool)value; }
   Value getValue() const {
     assert(value && "StructuredIndexed Value not set.");
     return value;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80497.265944.patch
Type: text/x-patch
Size: 2445 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200524/b16ba4f8/attachment-0001.bin>


More information about the llvm-commits mailing list