[Mlir-commits] [mlir] 43f6e04 - Make `mlir::OpState::operator bool` explicit

Mehdi Amini llvmlistbot at llvm.org
Mon May 17 10:29:33 PDT 2021


Author: Mehdi Amini
Date: 2021-05-17T17:29:25Z
New Revision: 43f6e04258aaece5b45c18986e0e6c3e690fa82e

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

LOG: Make `mlir::OpState::operator bool` explicit

This change makes the conversion of an mlir::OpState to bool `explicit`. Idiomatic boolean uses continue to work as before, but questionable implicit uses (e.g. accumulating over a range of OpStates to count "true" states) become ill-formed. This makes the class interface a lilttle less error-prone.

I tested this change on our internal (fairly large) codebase, and only one fix was needed, which was ultimately an improvement of the affected code.

Reviewed By: rriddle, mehdi_amini

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

Added: 
    

Modified: 
    mlir/include/mlir/IR/OpDefinition.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h
index b488dc12a481..735d59703029 100644
--- a/mlir/include/mlir/IR/OpDefinition.h
+++ b/mlir/include/mlir/IR/OpDefinition.h
@@ -93,8 +93,8 @@ void ensureRegionTerminator(
 /// they aren't customized.
 class OpState {
 public:
-  /// Ops are pointer-like, so we allow implicit conversion to bool.
-  operator bool() { return getOperation() != nullptr; }
+  /// Ops are pointer-like, so we allow conversion to bool.
+  explicit operator bool() { return getOperation() != nullptr; }
 
   /// This implicitly converts to Operation*.
   operator Operation *() const { return state; }


        


More information about the Mlir-commits mailing list