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

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Sun Jan 29 08:40:57 PST 2023


Author: Peter Klausler
Date: 2023-01-29T08:40:46-08:00
New Revision: eb1bd7086abaafb30e41d374d55e68b9f064d929

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

LOG: [flang] If it's got an argument keyword, it can't become an array reference

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.)

Differential Revision: https://reviews.llvm.org/D142765

Added: 
    flang/test/Semantics/call32.f90

Modified: 
    flang/lib/Semantics/expression.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 6099ec419e415..966884fb4c32a 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -3247,6 +3247,13 @@ static void FixMisparsedFunctionReference(
   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{

diff  --git a/flang/test/Semantics/call32.f90 b/flang/test/Semantics/call32.f90
new file mode 100644
index 0000000000000..80e9c02a7114c
--- /dev/null
+++ b/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


        


More information about the flang-commits mailing list