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, 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