[flang-commits] [flang] b313988 - [flang] Catch missed error cases of assumed-rank actual arguments (#182932)

via flang-commits flang-commits at lists.llvm.org
Thu Feb 26 06:58:17 PST 2026


Author: Peter Klausler
Date: 2026-02-26T06:58:12-08:00
New Revision: b313988735105d2664a87d6d1444a57414002d14

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

LOG: [flang] Catch missed error cases of assumed-rank actual arguments (#182932)

Assumed-rank actual arguments are acceptable to some intrinsic
procedures, and for association with assumed-rank dummy arguments, but
other cases are not allowed. We catch some, namely ELEMENTAL callees and
CHARACTER arguments, but not the general case error of an assumed-rank
array being associated with a non-assumed-rank dummy.

Added: 
    

Modified: 
    flang/lib/Semantics/check-call.cpp
    flang/test/Semantics/call03.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 0e32b56f40e64..3bfe69ca65f6c 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -435,6 +435,24 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
               actualDesc);
         }
       }
+    } else if (actualIsAssumedRank) {
+      if (actualType.type().category() != TypeCategory::Character &&
+          !intrinsic) {
+        // A more specific message will have already been emitted for
+        // assumed-rank argument that's CHARACTER, a callee that's ELEMENTAL,
+        // or an intrinsic procedure that can't handle assumed-rank.
+        if (!context.languageFeatures().IsEnabled(
+                common::LanguageFeature::AssumedRankPassedToNonAssumedRank)) {
+          messages.Say(
+              "Assumed-rank actual argument may not be associated with a %s that is not also assumed-rank"_err_en_US,
+              dummyName);
+        } else {
+          foldingContext.Warn(
+              common::LanguageFeature::AssumedRankPassedToNonAssumedRank,
+              "Assumed-rank actual argument should not be associated with a %s that is not also assumed-rank"_port_en_US,
+              dummyName);
+        }
+      }
     } else if (dummy.ignoreTKR.test(common::IgnoreTKR::Rank)) {
     } else if (dummyRank > 0 && !dummyIsAllocatableOrPointer &&
         !dummy.type.attrs().test(

diff  --git a/flang/test/Semantics/call03.f90 b/flang/test/Semantics/call03.f90
index 6a1009392f94b..557b1d4d10415 100644
--- a/flang/test/Semantics/call03.f90
+++ b/flang/test/Semantics/call03.f90
@@ -374,6 +374,7 @@ subroutine test15(assumedrank) ! C1539
     call volatileassumedsize(d(::2))
     !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='
     call volatilecontiguous(d(::2))
+    !ERROR: Assumed-rank actual argument may not be associated with a dummy argument 'x=' that is not also assumed-rank
     !ERROR: ASYNCHRONOUS or VOLATILE actual argument that is not simply contiguous may not be associated with a contiguous ASYNCHRONOUS or VOLATILE dummy argument 'x='
     call volatilecontiguous(assumedrank)
   end subroutine


        


More information about the flang-commits mailing list