[Mlir-commits] [mlir] 3b0dce5 - Use value_or (NFC)

Kazu Hirata llvmlistbot at llvm.org
Fri Jul 15 19:46:36 PDT 2022


Author: Kazu Hirata
Date: 2022-07-15T19:46:29-07:00
New Revision: 3b0dce5b8b1596c50360952a8fb031d52562ccf6

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

LOG: Use value_or (NFC)

Added: 
    

Modified: 
    clang/include/clang/APINotes/Types.h
    clang/lib/Frontend/InitPreprocessor.cpp
    mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/APINotes/Types.h b/clang/include/clang/APINotes/Types.h
index 0e5b43080e4bb..f155d6a063274 100644
--- a/clang/include/clang/APINotes/Types.h
+++ b/clang/include/clang/APINotes/Types.h
@@ -77,7 +77,7 @@ class CommonEntityInfo {
 
   void setSwiftPrivate(llvm::Optional<bool> Private) {
     SwiftPrivateSpecified = Private.has_value();
-    SwiftPrivate = Private ? *Private : 0;
+    SwiftPrivate = Private.value_or(0);
   }
 
   friend bool operator==(const CommonEntityInfo &, const CommonEntityInfo &);

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index d0360696ff9cb..655490ba06e5d 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -829,15 +829,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
 
     if (LangOpts.ObjCRuntime.getKind() == ObjCRuntime::ObjFW) {
       VersionTuple tuple = LangOpts.ObjCRuntime.getVersion();
-
-      unsigned minor = 0;
-      if (tuple.getMinor())
-        minor = tuple.getMinor().value();
-
-      unsigned subminor = 0;
-      if (tuple.getSubminor())
-        subminor = tuple.getSubminor().value();
-
+      unsigned minor = tuple.getMinor().value_or(0);
+      unsigned subminor = tuple.getSubminor().value_or(0);
       Builder.defineMacro("__OBJFW_RUNTIME_ABI__",
                           Twine(tuple.getMajor() * 10000 + minor * 100 +
                                 subminor));

diff  --git a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
index 146d9d0fc64ff..e4ae23e9bcde2 100644
--- a/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
+++ b/mlir/lib/Dialect/Bufferization/Transforms/BufferUtils.cpp
@@ -160,9 +160,7 @@ bufferization::getGlobalFor(arith::ConstantOp constantOp, uint64_t alignment) {
       continue;
     if (!globalOp.getInitialValue().has_value())
       continue;
-    uint64_t opAlignment = globalOp.getAlignment().has_value()
-                               ? globalOp.getAlignment().value()
-                               : 0;
+    uint64_t opAlignment = globalOp.getAlignment().value_or(0);
     Attribute initialValue = globalOp.getInitialValue().value();
     if (opAlignment == alignment && initialValue == constantOp.getValue())
       return globalOp;


        


More information about the Mlir-commits mailing list