From def02de9c48f6600d72a22010a33792610d6ab8c Mon Sep 17 00:00:00 2001 From: Eugene Epshteyn Date: Wed, 5 Nov 2025 20:01:49 -0500 Subject: [PATCH 1/3] [flang] Disallow passing array actual arguments to ignore_tkr(r) scalars with VALUE attribute --- flang/lib/Semantics/check-call.cpp | 7 ++++++- flang/test/Semantics/val-tkr.f90 | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 flang/test/Semantics/val-tkr.f90 diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index 995deaa12dd3b..054286af790ab 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -548,7 +548,12 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy, actualLastSymbol = &ResolveAssociations(*actualLastSymbol); } int actualRank{actualType.Rank()}; - if (dummy.type.attrs().test( + 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) { 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 From e7bf466d123bdee28dcd60d90a2da0b5d3d34c7d Mon Sep 17 00:00:00 2001 From: Eugene Epshteyn Date: Wed, 5 Nov 2025 20:04:01 -0500 Subject: [PATCH 2/3] clang-format --- flang/lib/Semantics/check-call.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp index 054286af790ab..53a22768855e1 100644 --- a/flang/lib/Semantics/check-call.cpp +++ b/flang/lib/Semantics/check-call.cpp @@ -551,10 +551,10 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy, 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); + "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)) { + characteristics::TypeAndShape::Attr::AssumedShape)) { // 15.5.2.4(16) if (actualIsAssumedRank) { messages.Say( From 9c0282de0210f52c2e2ce28d14a1110f01782685 Mon Sep 17 00:00:00 2001 From: Eugene Epshteyn Date: Thu, 6 Nov 2025 13:15:53 -0500 Subject: [PATCH 3/3] Updated directives docs with the new limitation --- flang/docs/Directives.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/flang/docs/Directives.md b/flang/docs/Directives.md index 2f16a8d579f8b..902f1530a2672 100644 --- a/flang/docs/Directives.md +++ b/flang/docs/Directives.md @@ -32,6 +32,22 @@ A list of non-standard directives supported by Flang end end interface ``` + Note that it's not allowed to pass array actual argument to `ignore_trk(R)` + dummy argument that is a scalar with `VALUE` attribute, for example: +``` + interface + subroutine s(b) + !dir$ ignore_tkr(r) b + integer, value :: b + end + end interface + integer :: a(5) + call s(a) +``` + The reason for this limitation is that scalars with `VALUE` attribute can + be passed in registers, so it's not clear how lowering should handle this + case. (Passing scalar actual argument to `ignore_tkr(R)` dummy argument + that is a scalar with `VALUE` attribute is allowed.) * `!dir$ assume_aligned desginator:alignment`, where designator is a variable, maybe with array indices, and alignment is what the compiler should assume the alignment to be. E.g A:64 or B(1,1,1):128. The alignment should be a power of 2,