Skip to content

Commit ea87d7c

Browse files
authored
[flang] Add control and a portability warning for an extension (#137995)
This compiler allows an element of an assumed-shape array or POINTER to be used in sequence association as an actual argument, so long as the array is declared to have the CONTIGUOUS attribute. Make sure that this extension is under control of a LanguageFeature enum, so that a hypothetical compiler driver option could disable it, and add an optional portability warning for its use.
1 parent 9c5f451 commit ea87d7c

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
5454
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
5555
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
5656
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
57-
IgnoreIrrelevantAttributes, Unsigned)
57+
IgnoreIrrelevantAttributes, Unsigned, ContiguousOkForSeqAssociation)
5858

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

flang/lib/Semantics/check-call.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -581,20 +581,38 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
581581
"Polymorphic scalar may not be associated with a %s array"_err_en_US,
582582
dummyName);
583583
}
584+
bool isOkBecauseContiguous{
585+
context.IsEnabled(
586+
common::LanguageFeature::ContiguousOkForSeqAssociation) &&
587+
actualLastSymbol &&
588+
evaluate::IsContiguous(*actualLastSymbol, foldingContext)};
584589
if (actualIsArrayElement && actualLastSymbol &&
585-
!evaluate::IsContiguous(*actualLastSymbol, foldingContext) &&
586590
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
587591
if (IsPointer(*actualLastSymbol)) {
588-
basicError = true;
589-
messages.Say(
590-
"Element of pointer array may not be associated with a %s array"_err_en_US,
591-
dummyName);
592+
if (isOkBecauseContiguous) {
593+
context.Warn(
594+
common::LanguageFeature::ContiguousOkForSeqAssociation,
595+
messages.at(),
596+
"Element of contiguous pointer array is accepted for storage sequence association"_port_en_US);
597+
} else {
598+
basicError = true;
599+
messages.Say(
600+
"Element of pointer array may not be associated with a %s array"_err_en_US,
601+
dummyName);
602+
}
592603
} else if (IsAssumedShape(*actualLastSymbol) &&
593604
!dummy.ignoreTKR.test(common::IgnoreTKR::Contiguous)) {
594-
basicError = true;
595-
messages.Say(
596-
"Element of assumed-shape array may not be associated with a %s array"_err_en_US,
597-
dummyName);
605+
if (isOkBecauseContiguous) {
606+
context.Warn(
607+
common::LanguageFeature::ContiguousOkForSeqAssociation,
608+
messages.at(),
609+
"Element of contiguous assumed-shape array is accepted for storage sequence association"_port_en_US);
610+
} else {
611+
basicError = true;
612+
messages.Say(
613+
"Element of assumed-shape array may not be associated with a %s array"_err_en_US,
614+
dummyName);
615+
}
598616
}
599617
}
600618
}

flang/test/Semantics/call44.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
2+
subroutine assumedshape(normal, contig)
3+
real normal(:)
4+
real, contiguous :: contig(:)
5+
!WARNING: If the procedure's interface were explicit, this reference would be in error
6+
!BECAUSE: Element of assumed-shape array may not be associated with a dummy argument 'assumedsize=' array
7+
call seqAssociate(normal(1))
8+
!PORTABILITY: Element of contiguous assumed-shape array is accepted for storage sequence association
9+
call seqAssociate(contig(1))
10+
end
11+
subroutine seqAssociate(assumedSize)
12+
real assumedSize(*)
13+
end

0 commit comments

Comments
 (0)