[flang-commits] [flang] e8572d0 - [flang] Don't emit conversion error for max(a, b, optionalCharacter) (#88156)

via flang-commits flang-commits at lists.llvm.org
Mon Apr 22 14:13:04 PDT 2024


Author: Peter Klausler
Date: 2024-04-22T14:13:00-07:00
New Revision: e8572d0fc9940512ead2e81ec731208cb0d9ee50

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

LOG: [flang] Don't emit conversion error for max(a,b, optionalCharacter) (#88156)

A recent patch added an error message for whole optional dummy argument
usage as optional arguments (third or later) to MAX and MIN when those
names required type conversion, since that conversion only works when
the optional arguments are present. This check shouldn't care about
character lengths. Make it so.

Added: 
    

Modified: 
    flang/lib/Semantics/check-call.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index bd2f755855172a..7d73b55dac328e 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1477,10 +1477,15 @@ static void CheckMaxMin(const characteristics::Procedure &proc,
         if (arguments[j]) {
           if (const auto *expr{arguments[j]->UnwrapExpr()};
               expr && evaluate::MayBePassedAsAbsentOptional(*expr)) {
-            if (auto thisType{expr->GetType()};
-                thisType && *thisType != typeAndShape->type()) {
-              messages.Say(arguments[j]->sourceLocation(),
-                  "An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE"_err_en_US);
+            if (auto thisType{expr->GetType()}) {
+              if (thisType->category() == TypeCategory::Character &&
+                  typeAndShape->type().category() == TypeCategory::Character &&
+                  thisType->kind() == typeAndShape->type().kind()) {
+                // don't care about lengths
+              } else if (*thisType != typeAndShape->type()) {
+                messages.Say(arguments[j]->sourceLocation(),
+                    "An actual argument to MAX/MIN requiring data conversion may not be OPTIONAL, POINTER, or ALLOCATABLE"_err_en_US);
+              }
             }
           }
         }


        


More information about the flang-commits mailing list