Skip to content

[flang] Catch whole assumed-size array passed to elemental #108239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

klausler
Copy link
Contributor

A whole assumed-size array is not a valid argument to an elemental procedure (intrinsic or otherwise).

@klausler klausler requested a review from jeanPerier September 11, 2024 15:32
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Sep 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 11, 2024

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

A whole assumed-size array is not a valid argument to an elemental procedure (intrinsic or otherwise).


Full diff: https://github.com/llvm/llvm-project/pull/108239.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-call.cpp (+8)
  • (added) flang/test/Semantics/elemental02.f90 (+13)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index c7ec8733655648..05f82626f3d52f 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1363,6 +1363,14 @@ static bool CheckElementalConformance(parser::ContextualMessages &messages,
     const auto &dummy{proc.dummyArguments.at(index++)};
     if (arg) {
       if (const auto *expr{arg->UnwrapExpr()}) {
+        if (const auto *actualLastSymbol{evaluate::GetLastSymbol(arg)}) {
+          actualLastSymbol = &ResolveAssociations(*actualLastSymbol);
+          if (IsAssumedSizeArray(*actualLastSymbol)) {
+            evaluate::SayWithDeclaration(messages, *actualLastSymbol,
+                "Whole assumed-size array '%s' may not be used as an argument to an elemental procedure"_err_en_US,
+                actualLastSymbol->name());
+          }
+        }
         if (auto argShape{evaluate::GetShape(context, *expr)}) {
           if (GetRank(*argShape) > 0) {
             std::string argName{"actual argument ("s + expr->AsFortran() +
diff --git a/flang/test/Semantics/elemental02.f90 b/flang/test/Semantics/elemental02.f90
new file mode 100644
index 00000000000000..7f8fb4a378b7eb
--- /dev/null
+++ b/flang/test/Semantics/elemental02.f90
@@ -0,0 +1,13 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+subroutine s(a)
+  real a(*)
+  interface
+    elemental function ef(efarg)
+      real, intent(in) :: efarg
+    end
+  end interface
+!ERROR: Whole assumed-size array 'a' may not be used as an argument to an elemental procedure
+  print *, sqrt(a)
+!ERROR: Whole assumed-size array 'a' may not be used as an argument to an elemental procedure
+  print *, ef(a)
+end

@klausler klausler requested a review from clementval September 11, 2024 18:44
Copy link
Contributor

@clementval clementval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

A whole assumed-size array is not a valid argument to an elemental
procedure (intrinsic or otherwise).
@klausler klausler merged commit 1595ca4 into llvm:main Sep 12, 2024
8 checks passed
@klausler klausler deleted the bug1720 branch September 12, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants