Skip to content

Commit 465807e

Browse files
authored
[flang] Catch missing "not a dummy argument" cases (#90268)
Declaration checking is looking for inappropriate usage of the INTENT, VALUE, & OPTIONAL attributes in multiple places, and some oddball cases like ENTRY points are not checked. Centralize the check for attributes that apply only to dummy arguments into one spot.
1 parent 7111304 commit 465807e

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,14 @@ void CheckHelper::Check(const Symbol &symbol) {
289289
messages_.Say(
290290
"An entity may not have the ASYNCHRONOUS attribute unless it is a variable"_err_en_US);
291291
}
292+
if (symbol.attrs().HasAny({Attr::INTENT_IN, Attr::INTENT_INOUT,
293+
Attr::INTENT_OUT, Attr::OPTIONAL, Attr::VALUE}) &&
294+
!IsDummy(symbol)) {
295+
messages_.Say(
296+
"Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute"_err_en_US);
297+
} else if (symbol.attrs().test(Attr::VALUE)) {
298+
CheckValue(symbol, derived);
299+
}
292300

293301
if (isDone) {
294302
return; // following checks do not apply
@@ -411,9 +419,6 @@ void CheckHelper::Check(const Symbol &symbol) {
411419
// The non-dummy case is a hard error that's caught elsewhere.
412420
}
413421
}
414-
if (symbol.attrs().test(Attr::VALUE)) {
415-
CheckValue(symbol, derived);
416-
}
417422
if (IsDummy(symbol)) {
418423
if (IsNamedConstant(symbol)) {
419424
messages_.Say(
@@ -527,13 +532,10 @@ void CheckHelper::CheckBindCFunctionResult(const Symbol &symbol) { // C1553
527532

528533
void CheckHelper::CheckValue(
529534
const Symbol &symbol, const DerivedTypeSpec *derived) { // C863 - C865
530-
if (!IsDummy(symbol)) {
531-
messages_.Say(
532-
"VALUE attribute may apply only to a dummy argument"_err_en_US);
533-
}
534535
if (IsProcedure(symbol)) {
535536
messages_.Say(
536537
"VALUE attribute may apply only to a dummy data object"_err_en_US);
538+
return; // don't pile on
537539
}
538540
if (IsAssumedSizeArray(symbol)) {
539541
messages_.Say(
@@ -786,14 +788,6 @@ void CheckHelper::CheckObjectEntity(
786788
}
787789
}
788790
}
789-
} else if (symbol.attrs().test(Attr::INTENT_IN) ||
790-
symbol.attrs().test(Attr::INTENT_OUT) ||
791-
symbol.attrs().test(Attr::INTENT_INOUT)) {
792-
messages_.Say(
793-
"INTENT attributes may apply only to a dummy argument"_err_en_US); // C843
794-
} else if (IsOptional(symbol)) {
795-
messages_.Say(
796-
"OPTIONAL attribute may apply only to a dummy argument"_err_en_US); // C849
797791
} else if (!details.ignoreTKR().empty()) {
798792
messages_.Say(
799793
"!DIR$ IGNORE_TKR directive may apply only to a dummy data argument"_err_en_US);
@@ -1214,9 +1208,8 @@ void CheckHelper::CheckProcEntity(
12141208
const Symbol *interface{details.procInterface()};
12151209
if (details.isDummy()) {
12161210
if (!symbol.attrs().test(Attr::POINTER) && // C843
1217-
(symbol.attrs().test(Attr::INTENT_IN) ||
1218-
symbol.attrs().test(Attr::INTENT_OUT) ||
1219-
symbol.attrs().test(Attr::INTENT_INOUT))) {
1211+
symbol.attrs().HasAny(
1212+
{Attr::INTENT_IN, Attr::INTENT_OUT, Attr::INTENT_INOUT})) {
12201213
messages_.Say("A dummy procedure without the POINTER attribute"
12211214
" may not have an INTENT attribute"_err_en_US);
12221215
}
@@ -1240,14 +1233,6 @@ void CheckHelper::CheckProcEntity(
12401233
messages_.Say("A dummy procedure may not be ELEMENTAL"_err_en_US);
12411234
}
12421235
}
1243-
} else if (symbol.attrs().test(Attr::INTENT_IN) ||
1244-
symbol.attrs().test(Attr::INTENT_OUT) ||
1245-
symbol.attrs().test(Attr::INTENT_INOUT)) {
1246-
messages_.Say("INTENT attributes may apply only to a dummy "
1247-
"argument"_err_en_US); // C843
1248-
} else if (IsOptional(symbol)) {
1249-
messages_.Say("OPTIONAL attribute may apply only to a dummy "
1250-
"argument"_err_en_US); // C849
12511236
} else if (IsPointer(symbol)) {
12521237
CheckPointerInitialization(symbol);
12531238
if (interface) {

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: VALUE attribute may apply only to a dummy argument
12+
!ERROR: Only a dummy argument may 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: INTENT attributes may apply only to a dummy argument
72+
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
7373
real, intent(in) :: local2
74-
!ERROR: INTENT attributes may apply only to a dummy argument
74+
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
7575
procedure(), intent(in) :: p1
76-
!ERROR: OPTIONAL attribute may apply only to a dummy argument
76+
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
7777
real, optional :: local3
78-
!ERROR: OPTIONAL attribute may apply only to a dummy argument
78+
!ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
7979
procedure(), optional :: p2
8080
end subroutine

0 commit comments

Comments
 (0)