Skip to content

[flang] Disallow passing array actual arguments to ignore_tkr(r) scalars with VALUE attribute#166682

Merged
eugeneepshteyn merged 3 commits intollvm:mainfrom
eugeneepshteyn:ignore-tkr-b-array-val
Nov 12, 2025
Merged

[flang] Disallow passing array actual arguments to ignore_tkr(r) scalars with VALUE attribute#166682
eugeneepshteyn merged 3 commits intollvm:mainfrom
eugeneepshteyn:ignore-tkr-b-array-val

Conversation

@eugeneepshteyn
Copy link
Contributor

Scalars with VALUE attribute are likely passed in registers, so it's now clear what lowering should do with the array actual argument in this case. Fail this case with an error before getting to lowering.

@eugeneepshteyn eugeneepshteyn marked this pull request as ready for review November 6, 2025 01:09
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Nov 6, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 6, 2025

@llvm/pr-subscribers-flang-semantics

Author: Eugene Epshteyn (eugeneepshteyn)

Changes

Scalars with VALUE attribute are likely passed in registers, so it's now clear what lowering should do with the array actual argument in this case. Fail this case with an error before getting to lowering.


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

2 Files Affected:

  • (modified) flang/lib/Semantics/check-call.cpp (+7-2)
  • (added) flang/test/Semantics/val-tkr.f90 (+22)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 995deaa12dd3b..53a22768855e1 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -548,8 +548,13 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
     actualLastSymbol = &ResolveAssociations(*actualLastSymbol);
   }
   int actualRank{actualType.Rank()};
-  if (dummy.type.attrs().test(
-          characteristics::TypeAndShape::Attr::AssumedShape)) {
+  if (dummyIsValue && dummyRank == 0 &&
+      dummy.ignoreTKR.test(common::IgnoreTKR::Rank) && actualRank > 0) {
+    messages.Say(
+        "Array actual argument may not be associated with IGNORE_TKR(R) scalar %s with VALUE attribute"_err_en_US,
+        dummyName);
+  } else if (dummy.type.attrs().test(
+                 characteristics::TypeAndShape::Attr::AssumedShape)) {
     // 15.5.2.4(16)
     if (actualIsAssumedRank) {
       messages.Say(
diff --git a/flang/test/Semantics/val-tkr.f90 b/flang/test/Semantics/val-tkr.f90
new file mode 100644
index 0000000000000..bed41f3ed0569
--- /dev/null
+++ b/flang/test/Semantics/val-tkr.f90
@@ -0,0 +1,22 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+implicit none
+interface
+  subroutine s(b)
+    !dir$ ignore_tkr(tr) b
+    real, value :: b
+  end
+  subroutine s1(b)
+    !dir$ ignore_tkr(r) b
+    integer, value :: b
+  end
+end interface
+integer :: a(5), a1
+! forbid array to scalar with VALUE and ignore_tkr(r)
+!ERROR: Array actual argument may not be associated with IGNORE_TKR(R) scalar dummy argument 'b=' with VALUE attribute
+call s(a)
+!ERROR: Array actual argument may not be associated with IGNORE_TKR(R) scalar dummy argument 'b=' with VALUE attribute
+call s1(a)
+! allow scalar to scalar with VALUE
+call s(a1)
+call s1(a(1))
+end

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks Eugene.

Can you update flang/docs/Directives.md to say a word about the VALUE case to explain when it is allowed and what to expect when allowed?

@eugeneepshteyn
Copy link
Contributor Author

Can you update flang/docs/Directives.md to say a word about the VALUE case to explain when it is allowed and what to expect when allowed?

Doc updated. Please review.

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

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

Thanks

@eugeneepshteyn eugeneepshteyn merged commit 4f8943d into llvm:main Nov 12, 2025
11 checks passed
@eugeneepshteyn eugeneepshteyn deleted the ignore-tkr-b-array-val branch November 12, 2025 11:04
git-crd pushed a commit to git-crd/crd-llvm-project that referenced this pull request Nov 13, 2025
…ars with VALUE attribute (llvm#166682)

Scalars with VALUE attribute are likely passed in registers, so it's now
clear what lowering should do with the array actual argument in this
case. Fail this case with an error before getting to lowering.
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.

4 participants