[flang] fold LOGICAL intrinsic calls

Folding of LOGICAL intrinsic procedure was missing in the front-end causing
crash when using it in parameter expressions.
Simply fold LOGICAL calls to evaluate::Convert<T>.

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

GitOrigin-RevId: 27899112c69836cb1e7bbb58df2f3471a882292c
diff --git a/lib/Evaluate/fold-logical.cpp b/lib/Evaluate/fold-logical.cpp
index 64e4bd8..455b3c2 100644
--- a/lib/Evaluate/fold-logical.cpp
+++ b/lib/Evaluate/fold-logical.cpp
@@ -106,6 +106,10 @@
         }
       }
     }
+  } else if (name == "logical") {
+    if (auto *expr{UnwrapExpr<Expr<SomeLogical>>(args[0])}) {
+      return Fold(context, ConvertToType<T>(std::move(*expr)));
+    }
   } else if (name == "merge") {
     return FoldMerge<T>(context, std::move(funcRef));
   } else if (name == "__builtin_ieee_support_datatype" ||
diff --git a/test/Evaluate/folding01.f90 b/test/Evaluate/folding01.f90
index 465b227..b12c6a0 100644
--- a/test/Evaluate/folding01.f90
+++ b/test/Evaluate/folding01.f90
@@ -30,6 +30,9 @@
   logical, parameter :: test_neqv3 = .NOT.(.false..NEQV..false.)
   logical, parameter :: test_neqv4 = .NOT.(.true..NEQV..true.)
 
+  logical, parameter :: test_logical1 = logical(logical(.true., 2))
+  logical, parameter :: test_logical2 = .NOT.logical(logical(.false., 2))
+
 ! Check integer intrinsic operator folding
 
 ! Check integer relational intrinsic operation folding