Skip to content

Commit c1c9929

Browse files
authored
[flang] Allow a few irrelevant attributes, with warning (#117374)
INTENT, VALUE, and OPTIONAL attributes apply only to dummy arguments. A couple older compilers accept them, usually with a warning, if they are applied to names that are not dummy arguments, and they show up in some older non-portable source code. Change these cases into stern warnings by default.
1 parent 6baf002 commit c1c9929

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
5353
NonBindCInteroperability, CudaManaged, CudaUnified,
5454
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
5555
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
56-
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank)
56+
SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
57+
IgnoreIrrelevantAttributes)
5758

5859
// Portability and suspicious usage warnings
5960
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,

flang/lib/Common/Fortran-features.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
4343
warnLanguage_.set(LanguageFeature::BadBranchTarget);
4444
warnLanguage_.set(LanguageFeature::HollerithPolymorphic);
4545
warnLanguage_.set(LanguageFeature::ListDirectedSize);
46+
warnLanguage_.set(LanguageFeature::IgnoreIrrelevantAttributes);
4647
warnUsage_.set(UsageWarning::ShortArrayActual);
4748
warnUsage_.set(UsageWarning::FoldingException);
4849
warnUsage_.set(UsageWarning::FoldingAvoidsRuntimeCrash);

flang/lib/Semantics/check-declarations.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,14 @@ void CheckHelper::Check(const Symbol &symbol) {
320320
if (symbol.attrs().HasAny({Attr::INTENT_IN, Attr::INTENT_INOUT,
321321
Attr::INTENT_OUT, Attr::OPTIONAL, Attr::VALUE}) &&
322322
!IsDummy(symbol)) {
323-
messages_.Say(
324-
"Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute"_err_en_US);
323+
if (context_.IsEnabled(
324+
common::LanguageFeature::IgnoreIrrelevantAttributes)) {
325+
context_.Warn(common::LanguageFeature::IgnoreIrrelevantAttributes,
326+
"Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute"_warn_en_US);
327+
} else {
328+
messages_.Say(
329+
"Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute"_err_en_US);
330+
}
325331
} else if (symbol.attrs().test(Attr::VALUE)) {
326332
CheckValue(symbol, derived);
327333
}

flang/test/Semantics/call14.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module m
99
!ERROR: VALUE attribute may apply only to a dummy data object
1010
subroutine C863(notData,assumedSize,coarray,coarrayComponent,assumedRank,assumedLen)
1111
external :: notData
12-
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
12+
!WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
1313
real, value :: notADummy
1414
value :: notData
1515
!ERROR: VALUE attribute may not apply to an assumed-size array

flang/test/Semantics/resolve58.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ subroutine s6()
6969

7070
!ERROR: Implied-shape array 'local1' must be a named constant or a dummy argument
7171
real, dimension (*) :: local1
72-
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
72+
!WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
7373
real, intent(in) :: local2
74-
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
74+
!WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
7575
procedure(), intent(in) :: p1
76-
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
76+
!WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
7777
real, optional :: local3
78-
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
78+
!WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
7979
procedure(), optional :: p2
8080
end subroutine

0 commit comments

Comments
 (0)