[Mlir-commits] [mlir] a9b5edc - Make mlir::Value's bool conversion operator explicit

Benjamin Kramer llvmlistbot at llvm.org
Mon May 25 09:22:40 PDT 2020


Author: Benjamin Kramer
Date: 2020-05-25T18:22:00+02:00
New Revision: a9b5edc5e2c4ec9d506b2c30465ee9f2dc21e5cc

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

LOG: Make mlir::Value's bool conversion operator explicit

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.

Differential Revision: https://reviews.llvm.org/D80497

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/EDSC/Builders.h b/mlir/include/mlir/EDSC/Builders.h
index a6045db3d998..70443608a251 100644
--- a/mlir/include/mlir/EDSC/Builders.h
+++ b/mlir/include/mlir/EDSC/Builders.h
@@ -303,7 +303,7 @@ struct StructuredIndexed {
            "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;

diff  --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h
index 74f504c25156..f5cb16f347ed 100644
--- a/mlir/include/mlir/IR/Value.h
+++ b/mlir/include/mlir/IR/Value.h
@@ -92,7 +92,7 @@ class Value {
     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;
   }

diff  --git a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
index f703a8c621e6..9868a14c2165 100644
--- a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
+++ b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
@@ -281,7 +281,8 @@ LogicalResult NDTransferOpHelper<TransferReadOp>::doReplace() {
     }
   });
 
-  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);

diff  --git a/mlir/lib/Parser/Parser.cpp b/mlir/lib/Parser/Parser.cpp
index f5ad1b65f1a1..d5108a4ed29e 100644
--- a/mlir/lib/Parser/Parser.cpp
+++ b/mlir/lib/Parser/Parser.cpp
@@ -3542,14 +3542,14 @@ ParseResult OperationParser::finalize() {
   // 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();


        


More information about the Mlir-commits mailing list