diff --git a/flang/lib/Evaluate/fold-character.cpp b/flang/lib/Evaluate/fold-character.cpp index a73ed52672bb1..385159ed2d5b7 100644 --- a/flang/lib/Evaluate/fold-character.cpp +++ b/flang/lib/Evaluate/fold-character.cpp @@ -79,7 +79,8 @@ Expr> FoldIntrinsicFunction( } else if (name == "min") { return FoldMINorMAX(context, std::move(funcRef), Ordering::Less); } else if (name == "minval") { - auto most{std::numeric_limits::max()}; + // Collating sequences correspond to positive integers (3.31) + SingleCharType most{0x7fffffff >> (8 * (4 - KIND))}; if (auto identity{Identity( StringType{most}, GetConstantLength(context, funcRef, 0))}) { return FoldMaxvalMinval(