[flang] Fix ARM/POWER test failure (folding20.f90)
authorpeter klausler <pklausler@nvidia.com>
Wed, 16 Jun 2021 23:37:20 +0000 (16:37 -0700)
committerpeter klausler <pklausler@nvidia.com>
Wed, 16 Jun 2021 23:41:08 +0000 (16:41 -0700)
Recent code for folding MINVAL() didn't allow for architectures
whose C/C++ char type is unsigned, so the value of the maximum
Fortran character was incorrect.  This was caught by the
folding20.f90 test.  The fix is to avoid numeric_limits<> and
use hard values for max signed integers of various character kinds.

Pushing into llvm-project/main to restore ARM/POWER buildbots.

flang/lib/Evaluate/fold-character.cpp

index a73ed52..385159e 100644 (file)
@@ -79,7 +79,8 @@ Expr<Type<TypeCategory::Character, KIND>> FoldIntrinsicFunction(
   } else if (name == "min") {
     return FoldMINorMAX(context, std::move(funcRef), Ordering::Less);
   } else if (name == "minval") {
-    auto most{std::numeric_limits<SingleCharType>::max()};
+    // Collating sequences correspond to positive integers (3.31)
+    SingleCharType most{0x7fffffff >> (8 * (4 - KIND))};
     if (auto identity{Identity<T>(
             StringType{most}, GetConstantLength(context, funcRef, 0))}) {
       return FoldMaxvalMinval<T>(