[flang-commits] [flang] 1595ca4 - [flang] Catch whole assumed-size array passed to elemental (#108239)
via flang-commits
flang-commits at lists.llvm.org
Thu Sep 12 09:11:26 PDT 2024
Author: Peter Klausler
Date: 2024-09-12T09:11:23-07:00
New Revision: 1595ca435ca9e85a3f693267b5f928bf3cfc2cc1
URL: https://github.com/llvm/llvm-project/commit/1595ca435ca9e85a3f693267b5f928bf3cfc2cc1
DIFF: https://github.com/llvm/llvm-project/commit/1595ca435ca9e85a3f693267b5f928bf3cfc2cc1.diff
LOG: [flang] Catch whole assumed-size array passed to elemental (#108239)
A whole assumed-size array is not a valid argument to an elemental
procedure (intrinsic or otherwise).
Added:
flang/test/Semantics/elemental02.f90
Modified:
flang/lib/Semantics/check-call.cpp
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index c7ec8733655648..71d1c083c31278 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 *wholeSymbol{evaluate::UnwrapWholeSymbolDataRef(arg)}) {
+ wholeSymbol = &ResolveAssociations(*wholeSymbol);
+ if (IsAssumedSizeArray(*wholeSymbol)) {
+ evaluate::SayWithDeclaration(messages, *wholeSymbol,
+ "Whole assumed-size array '%s' may not be used as an argument to an elemental procedure"_err_en_US,
+ wholeSymbol->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
More information about the flang-commits
mailing list