[llvm] [llvm] Use std::optional::value_or (NFC) (PR #109890)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 24 17:58:28 PDT 2024


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/109890

None

>From e2d80bbefbfc423649852bff54607dda004c0095 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 24 Sep 2024 14:14:21 -0700
Subject: [PATCH] [llvm] Use std::optional::value_or (NFC)

---
 llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h | 3 +--
 llvm/tools/llvm-cov/SourceCoverageViewText.cpp              | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
index b93bc594a82bf3..4bdfa1cf4c1490 100644
--- a/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
+++ b/llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h
@@ -916,8 +916,7 @@ bool ConstructDecompositionT<C, H>::applyClause(
            /*ReductionIdentifiers=*/std::get<ReductionIdentifiers>(clause.t),
            /*List=*/objects}});
 
-  ReductionModifier effective =
-      modifier.has_value() ? *modifier : ReductionModifier::Default;
+  ReductionModifier effective = modifier.value_or(ReductionModifier::Default);
   bool effectiveApplied = false;
   // Walk over the leaf constructs starting from the innermost, and apply
   // the clause as required by the spec.
diff --git a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
index cab60c2d9034ed..8b93b592910b3d 100644
--- a/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageViewText.cpp
@@ -179,7 +179,7 @@ void SourceCoverageViewText::renderLine(raw_ostream &OS, LineRef L,
   unsigned Col = 1;
   for (const auto *S : Segments) {
     unsigned End = std::min(S->Col, static_cast<unsigned>(Line.size()) + 1);
-    colored_ostream(OS, Highlight ? *Highlight : raw_ostream::SAVEDCOLOR,
+    colored_ostream(OS, Highlight.value_or(raw_ostream::SAVEDCOLOR),
                     getOptions().Colors && Highlight, /*Bold=*/false,
                     /*BG=*/true)
         << Line.substr(Col - 1, End - Col);
@@ -196,7 +196,7 @@ void SourceCoverageViewText::renderLine(raw_ostream &OS, LineRef L,
   }
 
   // Show the rest of the line.
-  colored_ostream(OS, Highlight ? *Highlight : raw_ostream::SAVEDCOLOR,
+  colored_ostream(OS, Highlight.value_or(raw_ostream::SAVEDCOLOR),
                   getOptions().Colors && Highlight, /*Bold=*/false, /*BG=*/true)
       << Line.substr(Col - 1, Line.size() - Col + 1);
   OS << '\n';



More information about the llvm-commits mailing list