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

Peter Klausler via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 17:36:39 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGbddfb81a312e: [flang] Accept sparse argument keyword names for MAX/MIN (authored by klausler).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D117701/new/

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;
       }
     }
@@ -1808,8 +1808,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.401459.patch
Type: text/x-patch
Size: 2291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220120/404dcad1/attachment.bin>


More information about the llvm-commits mailing list