Skip to content

Commit 3beff22

Browse files
committed
[flang] Add documentation, control, and portability warning for extension
f18 allows, as an extension, an assumed-rank array to be storage sequence associated with a dummy argument. Document the extension, make it disableable, and add an optional portability warning. Fixes #114080.
1 parent 7b9f988 commit 3beff22

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

flang/docs/Extensions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ end
391391
has the SAVE attribute and was initialized.
392392
* `PRINT namelistname` is accepted and interpreted as
393393
`WRITE(*,NML=namelistname)`, a near-universal extension.
394+
* An assumed-rank array can be storage associated with a non-assumed-rank
395+
dummy array if it otherwise meets the requirements for storage association
396+
in F'2023 15.5.2.12.
394397

395398
### Extensions supported when enabled by options
396399

flang/include/flang/Common/Fortran-features.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
5353
NonBindCInteroperability, CudaManaged, CudaUnified,
5454
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
5555
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
56-
SavedLocalInSpecExpr, PrintNamelist)
56+
SavedLocalInSpecExpr, PrintNamelist, AssumedRankSequenceAssociation)
5757

5858
// Portability and suspicious usage warnings
5959
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,

flang/lib/Semantics/check-call.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,18 @@ static void CheckCharacterActual(evaluate::Expr<evaluate::SomeType> &actual,
135135
dummy.type.type().kind() == actualType.type().kind() &&
136136
!dummy.attrs.test(
137137
characteristics::DummyDataObject::Attr::DeducedFromActual)) {
138+
bool actualIsAssumedRank{evaluate::IsAssumedRank(actual)};
139+
if (actualIsAssumedRank) {
140+
if (!context.languageFeatures().IsEnabled(
141+
common::LanguageFeature::AssumedRankSequenceAssociation)) {
142+
messages.Say(
143+
"Assumed-rank character array may not be storage sequence associated with a dummy argument"_err_en_US);
144+
} else {
145+
context.Warn(common::LanguageFeature::AssumedRankSequenceAssociation,
146+
messages.at(),
147+
"Assumed-rank character array should not be storage sequence associated with a dummy argument"_port_en_US);
148+
}
149+
}
138150
if (dummy.type.LEN() && actualType.LEN()) {
139151
evaluate::FoldingContext &foldingContext{context.foldingContext()};
140152
auto dummyLength{
@@ -148,7 +160,7 @@ static void CheckCharacterActual(evaluate::Expr<evaluate::SomeType> &actual,
148160
if (auto dummySize{evaluate::ToInt64(evaluate::Fold(
149161
foldingContext, evaluate::GetSize(dummy.type.shape())))}) {
150162
auto dummyChars{*dummySize * *dummyLength};
151-
if (actualType.Rank() == 0) {
163+
if (actualType.Rank() == 0 && !actualIsAssumedRank) {
152164
evaluate::DesignatorFolder folder{
153165
context.foldingContext(), /*getLastComponent=*/true};
154166
if (auto actualOffset{folder.FoldDesignator(actual)}) {
@@ -602,7 +614,18 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
602614
characteristics::DummyDataObject::Attr::DeducedFromActual)) {
603615
if (auto dummySize{evaluate::ToInt64(evaluate::Fold(
604616
foldingContext, evaluate::GetSize(dummy.type.shape())))}) {
605-
if (actualRank == 0 && !actualIsAssumedRank) {
617+
if (actualIsAssumedRank) {
618+
if (!context.languageFeatures().IsEnabled(
619+
common::LanguageFeature::AssumedRankSequenceAssociation)) {
620+
messages.Say(
621+
"Assumed-rank array may not be storage sequence associated with a dummy argument"_err_en_US);
622+
} else {
623+
context.Warn(
624+
common::LanguageFeature::AssumedRankSequenceAssociation,
625+
messages.at(),
626+
"Assumed-rank array should not be storage sequence associated with a dummy argument"_port_en_US);
627+
}
628+
} else if (actualRank == 0) {
606629
if (evaluate::IsArrayElement(actual)) {
607630
// Actual argument is a scalar array element
608631
evaluate::DesignatorFolder folder{
@@ -643,7 +666,7 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
643666
}
644667
}
645668
}
646-
} else { // actualRank > 0 || actualIsAssumedRank
669+
} else {
647670
if (auto actualSize{evaluate::ToInt64(evaluate::Fold(
648671
foldingContext, evaluate::GetSize(actualType.shape())))};
649672
actualSize && *actualSize < *dummySize) {

flang/test/Semantics/call38.f90

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,3 +522,20 @@ subroutine test
522522
call scalar('a')
523523
end
524524
end
525+
526+
subroutine bug114080(arg)
527+
character(*) :: arg(..)
528+
interface
529+
subroutine sub1(arg1) bind(c)
530+
character(1) :: arg1(2,4)
531+
end subroutine
532+
end interface
533+
!WARNING: Assumed-rank character array should not be storage sequence associated with a dummy argument
534+
call sub1(arg)
535+
!WARNING: Assumed-rank character array should not be storage sequence associated with a dummy argument
536+
call sub2(arg)
537+
contains
538+
subroutine sub2(arg2)
539+
character(*) :: arg2(10)
540+
end subroutine sub2
541+
end subroutine

0 commit comments

Comments
 (0)