Skip to content

Commit 4f8943d

Browse files
[flang] Disallow passing array actual arguments to ignore_tkr(r) scalars with VALUE attribute (#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.
1 parent cf51a5e commit 4f8943d

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

flang/docs/Directives.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,22 @@ A list of non-standard directives supported by Flang
3232
end
3333
end interface
3434
```
35+
Note that it's not allowed to pass array actual argument to `ignore_trk(R)`
36+
dummy argument that is a scalar with `VALUE` attribute, for example:
37+
```
38+
interface
39+
subroutine s(b)
40+
!dir$ ignore_tkr(r) b
41+
integer, value :: b
42+
end
43+
end interface
44+
integer :: a(5)
45+
call s(a)
46+
```
47+
The reason for this limitation is that scalars with `VALUE` attribute can
48+
be passed in registers, so it's not clear how lowering should handle this
49+
case. (Passing scalar actual argument to `ignore_tkr(R)` dummy argument
50+
that is a scalar with `VALUE` attribute is allowed.)
3551
* `!dir$ assume_aligned desginator:alignment`, where designator is a variable,
3652
maybe with array indices, and alignment is what the compiler should assume the
3753
alignment to be. E.g A:64 or B(1,1,1):128. The alignment should be a power of 2,

flang/lib/Semantics/check-call.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,13 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
548548
actualLastSymbol = &ResolveAssociations(*actualLastSymbol);
549549
}
550550
int actualRank{actualType.Rank()};
551-
if (dummy.type.attrs().test(
552-
characteristics::TypeAndShape::Attr::AssumedShape)) {
551+
if (dummyIsValue && dummyRank == 0 &&
552+
dummy.ignoreTKR.test(common::IgnoreTKR::Rank) && actualRank > 0) {
553+
messages.Say(
554+
"Array actual argument may not be associated with IGNORE_TKR(R) scalar %s with VALUE attribute"_err_en_US,
555+
dummyName);
556+
} else if (dummy.type.attrs().test(
557+
characteristics::TypeAndShape::Attr::AssumedShape)) {
553558
// 15.5.2.4(16)
554559
if (actualIsAssumedRank) {
555560
messages.Say(

flang/test/Semantics/val-tkr.f90

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
implicit none
3+
interface
4+
subroutine s(b)
5+
!dir$ ignore_tkr(tr) b
6+
real, value :: b
7+
end
8+
subroutine s1(b)
9+
!dir$ ignore_tkr(r) b
10+
integer, value :: b
11+
end
12+
end interface
13+
integer :: a(5), a1
14+
! forbid array to scalar with VALUE and ignore_tkr(r)
15+
!ERROR: Array actual argument may not be associated with IGNORE_TKR(R) scalar dummy argument 'b=' with VALUE attribute
16+
call s(a)
17+
!ERROR: Array actual argument may not be associated with IGNORE_TKR(R) scalar dummy argument 'b=' with VALUE attribute
18+
call s1(a)
19+
! allow scalar to scalar with VALUE
20+
call s(a1)
21+
call s1(a(1))
22+
end

0 commit comments

Comments
 (0)