[flang-commits] [PATCH] D142765: [flang] If it's got an argument keyword, it can't become an array reference

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Fri Jan 27 09:49:13 PST 2023


klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.

Array references like A(1) are commonly misparsed as function references,
since the parser has almost no semantic context, and the parse tree is
fixed up later by semantics once it can be disambiguated.  In a case  
like A(I=1), however, the presence of an argument keyword must prevent  
conversion into an array reference.  (It might still also be a structure
constructor.)


https://reviews.llvm.org/D142765

Files:
  flang/lib/Semantics/expression.cpp
  flang/test/Semantics/call32.f90


Index: flang/test/Semantics/call32.f90
===================================================================
--- /dev/null
+++ flang/test/Semantics/call32.f90
@@ -0,0 +1,8 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
+! Ensure that a seemingly misparsed function reference is
+! not converted to an array references of the same name if
+! there's an argument keyword.
+real array(1)
+!ERROR: 'array' is not a callable procedure
+print *, array(argument=1)
+end
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -3140,6 +3140,13 @@
   if (auto *func{
           std::get_if<common::Indirection<parser::FunctionReference>>(&u)}) {
     parser::FunctionReference &funcRef{func->value()};
+    // Ensure that there are no argument keywords
+    for (const auto &arg :
+        std::get<std::list<parser::ActualArgSpec>>(funcRef.v.t)) {
+      if (std::get<std::optional<parser::Keyword>>(arg.t)) {
+        return;
+      }
+    }
     auto &proc{std::get<parser::ProcedureDesignator>(funcRef.v.t)};
     if (Symbol *origSymbol{
             common::visit(common::visitors{


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142765.492823.patch
Type: text/x-patch
Size: 1223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230127/1c104704/attachment.bin>


More information about the flang-commits mailing list