Skip to content

Commit 50e2581

Browse files
authored
[flang] Allow assumed-shape element pass to dummy arg with ignore_tkr (#78196)
This is allowed by gfortran and ifort with `![GCC|DEC]$ ATTRIBUTES NO_ARG_CHECK`
1 parent ee0b4d9 commit 50e2581

File tree

6 files changed

+31
-18
lines changed

6 files changed

+31
-18
lines changed

flang/docs/Directives.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ A list of non-standard directives supported by Flang
1818
The directive allow actual arguments that would otherwise be diagnosed
1919
as incompatible in type (T), kind (K), rank (R), CUDA device (D), or
2020
managed (M) status. The letter (A) is a shorthand for all of these,
21-
and is the default when no letters appear. The letter (C) is a legacy
22-
no-op. For example, if one wanted to call a "set all bytes to zero"
23-
utility that could be applied to arrays of any type or rank:
21+
and is the default when no letters appear. The letter (C) checks for
22+
contiguity for example allowing an element of an assumed-shape array to be
23+
passed as a dummy argument. For example, if one wanted to call a "set all
24+
bytes to zero" utility that could be applied to arrays of any type or rank:
2425
```
2526
interface
2627
subroutine clear(arr,bytes)

flang/include/flang/Common/Fortran.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ ENUM_CLASS(IgnoreTKR,
105105
Rank, // R - don't check ranks
106106
Device, // D - don't check host/device residence
107107
Managed, // M - don't check managed storage
108-
Contiguous) // C - legacy; disabled NVFORTRAN's convention that leading
109-
// dimension of assumed-shape was contiguous
108+
Contiguous) // C - don't check for storage sequence association with a
109+
// potentially non-contiguous object
110110
using IgnoreTKRSet = EnumSet<IgnoreTKR, 8>;
111111
// IGNORE_TKR(A) = IGNORE_TKR(TKRDM)
112112
static constexpr IgnoreTKRSet ignoreTKRAll{IgnoreTKR::Type, IgnoreTKR::Kind,

flang/lib/Semantics/check-call.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -529,13 +529,15 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
529529
dummyName);
530530
}
531531
if (actualIsArrayElement && actualLastSymbol &&
532-
!evaluate::IsContiguous(*actualLastSymbol, foldingContext)) {
532+
!evaluate::IsContiguous(*actualLastSymbol, foldingContext) &&
533+
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
533534
if (IsPointer(*actualLastSymbol)) {
534535
basicError = true;
535536
messages.Say(
536537
"Element of pointer array may not be associated with a %s array"_err_en_US,
537538
dummyName);
538-
} else if (IsAssumedShape(*actualLastSymbol)) {
539+
} else if (IsAssumedShape(*actualLastSymbol) &&
540+
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
539541
basicError = true;
540542
messages.Say(
541543
"Element of assumed-shape array may not be associated with a %s array"_err_en_US,

flang/lib/Semantics/check-declarations.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,6 @@ void CheckHelper::CheckObjectEntity(
746746
messages_.Say(
747747
"!DIR$ IGNORE_TKR may apply only in an interface or a module procedure"_err_en_US);
748748
}
749-
if (ignoreTKR.test(common::IgnoreTKR::Contiguous) &&
750-
!IsAssumedShape(symbol)) {
751-
messages_.Say(
752-
"!DIR$ IGNORE_TKR(C) may apply only to an assumed-shape array"_err_en_US);
753-
}
754749
if (ownerSymbol && ownerSymbol->attrs().test(Attr::ELEMENTAL) &&
755750
details.ignoreTKR().test(common::IgnoreTKR::Rank)) {
756751
messages_.Say(

flang/test/Semantics/ignore_tkr01.f90

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ subroutine t20(x)
138138
end block
139139
end
140140

141-
subroutine t21(x)
142-
!dir$ ignore_tkr(c) x
143-
!ERROR: !DIR$ IGNORE_TKR(C) may apply only to an assumed-shape array
144-
real x(1)
145-
end
146-
147141
subroutine t22(x)
148142
!dir$ ignore_tkr(r) x
149143
!WARNING: !DIR$ IGNORE_TKR(R) is not meaningful for an assumed-rank array

flang/test/Semantics/ignore_tkr03.f90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
! RUN: %flang_fc1 -fdebug-unparse %s 2>&1 | FileCheck %s
2+
module library
3+
contains
4+
subroutine lib_sub(buf)
5+
!dir$ ignore_tkr(c) buf
6+
real :: buf(1:*)
7+
end subroutine
8+
end module
9+
10+
module user
11+
use library
12+
contains
13+
subroutine sub(var, ptr)
14+
real :: var(:,:,:)
15+
real, pointer :: ptr(:)
16+
! CHECK: CALL lib_sub
17+
call lib_sub(var(1, 2, 3))
18+
! CHECK: CALL lib_sub
19+
call lib_sub(ptr(1))
20+
end subroutine
21+
end module

0 commit comments

Comments
 (0)