[flang-commits] [flang] [flang] Short-circuit scalar .AND./.OR. guarded by PRESENT() (PR #201524)

via flang-commits flang-commits at lists.llvm.org
Thu Jun 4 01:04:10 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- flang/lib/Lower/ConvertExprToHLFIR.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp
index 5b40d6ebc..d59dca5fc 100644
--- a/flang/lib/Lower/ConvertExprToHLFIR.cpp
+++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp
@@ -59,13 +59,11 @@ static bool isParenthesized(const Fortran::evaluate::Expr<T> &expr) {
 /// present once the presence test is true.
 template <typename A>
 static bool exprReferencesPresent(const A &expr) {
-  struct PresentFinder
-      : public Fortran::evaluate::AnyTraverse<PresentFinder> {
-    PresentFinder()
-        : Fortran::evaluate::AnyTraverse<PresentFinder>(*this) {}
+  struct PresentFinder : public Fortran::evaluate::AnyTraverse<PresentFinder> {
+    PresentFinder() : Fortran::evaluate::AnyTraverse<PresentFinder>(*this) {}
     using Fortran::evaluate::AnyTraverse<PresentFinder>::operator();
-    bool operator()(const Fortran::evaluate::SpecificIntrinsic &intrinsic)
-        const {
+    bool
+    operator()(const Fortran::evaluate::SpecificIntrinsic &intrinsic) const {
       return intrinsic.name == "present";
     }
   } finder;
@@ -1747,23 +1745,25 @@ private:
     auto genConst = [&](bool value) {
       fir::ResultOp::create(
           builder, loc,
-          builder.createConvert(loc, resultType, builder.createBool(loc, value)));
+          builder.createConvert(loc, resultType,
+                                builder.createBool(loc, value)));
     };
 
     // .AND.: left true  -> result is rhs, left false -> result is .false.
     // .OR. : left true  -> result is .true., left false -> result is rhs.
     const bool isAnd = logicalOp == Fortran::evaluate::LogicalOperator::And;
-    mlir::Value result =
-        isAnd ? builder.genIfOp(loc, {resultType}, cond,
-                                /*withElseRegion=*/true)
-                    .genThen([&]() { genRhs(); })
-                    .genElse([&]() { genConst(false); })
-                    .getResults()[0]
-              : builder.genIfOp(loc, {resultType}, cond,
-                                /*withElseRegion=*/true)
-                    .genThen([&]() { genConst(true); })
-                    .genElse([&]() { genRhs(); })
-                    .getResults()[0];
+    mlir::Value result = isAnd ? builder
+                                     .genIfOp(loc, {resultType}, cond,
+                                              /*withElseRegion=*/true)
+                                     .genThen([&]() { genRhs(); })
+                                     .genElse([&]() { genConst(false); })
+                                     .getResults()[0]
+                               : builder
+                                     .genIfOp(loc, {resultType}, cond,
+                                              /*withElseRegion=*/true)
+                                     .genThen([&]() { genConst(true); })
+                                     .genElse([&]() { genRhs(); })
+                                     .getResults()[0];
     return hlfir::EntityWithAttributes{result};
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/201524


More information about the flang-commits mailing list