[flang-commits] [PATCH] D117701: [flang] Accept sparse argument keyword names for MAX/MIN

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Wed Jan 19 10:17:12 PST 2022


klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
klausler requested review of this revision.

Accept any keyword argument names of the form "An" for
values of n >= 3 in calls to the intrinsic functions MAX, MIN,
and their variants, so long as "n" has no leading zero and
all the keywords are distinct.  Previously, f18 was needlessly
requiring the names to be contiguous.  When synthesizing keywords
to characterize the procedure's interface, don't conflict with
the program's keywords.


https://reviews.llvm.org/D117701

Files:
  flang/lib/Evaluate/intrinsics.cpp
  flang/test/Semantics/call23.f90


Index: flang/test/Semantics/call23.f90
===================================================================
--- flang/test/Semantics/call23.f90
+++ flang/test/Semantics/call23.f90
@@ -5,6 +5,8 @@
 print *, max(a1=x,a1=1)
 !ERROR: Keyword argument 'a1=' has already been specified positionally (#1) in this procedure reference
 print *, max(x,a1=1)
-!ERROR: Argument keyword 'a6=' is not recognized for this procedure reference
-print *, max(a1=x,a2=0,a3=0,a4=0,a6=0)
+print *, max(a1=x,a2=0,a4=0) ! ok
+print *, max(x,0,a99=0) ! ok
+!ERROR: Argument keyword 'a06=' is not known in call to 'max'
+print *, max(a1=x,a2=0,a06=0)
 end
Index: flang/lib/Evaluate/intrinsics.cpp
===================================================================
--- flang/lib/Evaluate/intrinsics.cpp
+++ flang/lib/Evaluate/intrinsics.cpp
@@ -1183,7 +1183,7 @@
 }
 
 // Ensure that the keywords of arguments to MAX/MIN and their variants
-// are of the form A123 with no duplicates.
+// are of the form A123 with no duplicates or leading zeroes.
 static bool CheckMaxMinArgument(std::optional<parser::CharBlock> keyword,
     std::set<parser::CharBlock> &set, const char *intrinsicName,
     parser::ContextualMessages &messages) {
@@ -1191,7 +1191,7 @@
     std::size_t j{1};
     for (; j < keyword->size(); ++j) {
       char ch{(*keyword)[j]};
-      if (ch < '0' || ch > '9') {
+      if (ch < (j == 1 ? '1' : '0') || ch > '9') {
         break;
       }
     }
@@ -1801,8 +1801,19 @@
     if (const auto &arg{rearranged[j]}) {
       if (const Expr<SomeType> *expr{arg->UnwrapExpr()}) {
         std::string kw{d.keyword};
-        if (isMaxMin) {
-          kw = "a"s + std::to_string(j + 1);
+        if (arg->keyword()) {
+          kw = arg->keyword()->ToString();
+        } else if (isMaxMin) {
+          for (std::size_t k{j + 1};; ++k) {
+            kw = "a"s + std::to_string(k);
+            auto iter{std::find_if(dummyArgs.begin(), dummyArgs.end(),
+                [&kw](const characteristics::DummyArgument &prev) {
+                  return prev.name == kw;
+                })};
+            if (iter == dummyArgs.end()) {
+              break;
+            }
+          }
         }
         auto dc{characteristics::DummyArgument::FromActual(
             std::move(kw), *expr, context)};


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117701.401321.patch
Type: text/x-patch
Size: 2291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220119/b29414c2/attachment-0001.bin>


More information about the flang-commits mailing list