[flang-commits] [flang] 2789911 - [flang] fold LOGICAL intrinsic calls

Jean Perier via flang-commits flang-commits at lists.llvm.org
Thu Mar 25 10:38:45 PDT 2021


Author: Jean Perier
Date: 2021-03-25T18:38:19+01:00
New Revision: 27899112c69836cb1e7bbb58df2f3471a882292c

URL: https://github.com/llvm/llvm-project/commit/27899112c69836cb1e7bbb58df2f3471a882292c
DIFF: https://github.com/llvm/llvm-project/commit/27899112c69836cb1e7bbb58df2f3471a882292c.diff

LOG: [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

Added: 
    

Modified: 
    flang/lib/Evaluate/fold-logical.cpp
    flang/test/Evaluate/folding01.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/fold-logical.cpp b/flang/lib/Evaluate/fold-logical.cpp
index 64e4bd8c8bd9..455b3c2605c3 100644
--- a/flang/lib/Evaluate/fold-logical.cpp
+++ b/flang/lib/Evaluate/fold-logical.cpp
@@ -106,6 +106,10 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
         }
       }
     }
+  } 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/flang/test/Evaluate/folding01.f90 b/flang/test/Evaluate/folding01.f90
index 465b22752cec..b12c6a0e9aed 100644
--- a/flang/test/Evaluate/folding01.f90
+++ b/flang/test/Evaluate/folding01.f90
@@ -30,6 +30,9 @@ module m
   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


        


More information about the flang-commits mailing list