-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang] Allow a few irrelevant attributes, with warning #117374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
@llvm/pr-subscribers-flang-semantics Author: Peter Klausler (klausler) ChangesINTENT, 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. Full diff: https://github.com/llvm/llvm-project/pull/117374.diff 5 Files Affected:
diff --git a/flang/include/flang/Common/Fortran-features.h b/flang/include/flang/Common/Fortran-features.h
index c6ab846cce2fc0..9e3fd0dcca8e17 100644
--- a/flang/include/flang/Common/Fortran-features.h
+++ b/flang/include/flang/Common/Fortran-features.h
@@ -53,7 +53,8 @@ ENUM_CLASS(LanguageFeature, BackslashEscapes, OldDebugLines,
NonBindCInteroperability, CudaManaged, CudaUnified,
PolymorphicActualAllocatableOrPointerToMonomorphicDummy, RelaxedPureDummy,
UndefinableAsynchronousOrVolatileActual, AutomaticInMainProgram, PrintCptr,
- SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank)
+ SavedLocalInSpecExpr, PrintNamelist, AssumedRankPassedToNonAssumedRank,
+ IgnoreIrrelevantAttributes)
// Portability and suspicious usage warnings
ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
diff --git a/flang/lib/Common/Fortran-features.cpp b/flang/lib/Common/Fortran-features.cpp
index f47a4f17a6ba48..c86432874b8d83 100644
--- a/flang/lib/Common/Fortran-features.cpp
+++ b/flang/lib/Common/Fortran-features.cpp
@@ -43,6 +43,7 @@ LanguageFeatureControl::LanguageFeatureControl() {
warnLanguage_.set(LanguageFeature::BadBranchTarget);
warnLanguage_.set(LanguageFeature::HollerithPolymorphic);
warnLanguage_.set(LanguageFeature::ListDirectedSize);
+ warnLanguage_.set(LanguageFeature::IgnoreIrrelevantAttributes);
warnUsage_.set(UsageWarning::ShortArrayActual);
warnUsage_.set(UsageWarning::FoldingException);
warnUsage_.set(UsageWarning::FoldingAvoidsRuntimeCrash);
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index c9656d031b2e17..99c6e16c4260f1 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -320,8 +320,14 @@ void CheckHelper::Check(const Symbol &symbol) {
if (symbol.attrs().HasAny({Attr::INTENT_IN, Attr::INTENT_INOUT,
Attr::INTENT_OUT, Attr::OPTIONAL, Attr::VALUE}) &&
!IsDummy(symbol)) {
- messages_.Say(
- "Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute"_err_en_US);
+ if (context_.IsEnabled(
+ common::LanguageFeature::IgnoreIrrelevantAttributes)) {
+ context_.Warn(common::LanguageFeature::IgnoreIrrelevantAttributes,
+ "Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute"_warn_en_US);
+ } else {
+ messages_.Say(
+ "Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute"_err_en_US);
+ }
} else if (symbol.attrs().test(Attr::VALUE)) {
CheckValue(symbol, derived);
}
diff --git a/flang/test/Semantics/call14.f90 b/flang/test/Semantics/call14.f90
index e586d4eebd2535..fba11d35790b2e 100644
--- a/flang/test/Semantics/call14.f90
+++ b/flang/test/Semantics/call14.f90
@@ -9,7 +9,7 @@ module m
!ERROR: VALUE attribute may apply only to a dummy data object
subroutine C863(notData,assumedSize,coarray,coarrayComponent,assumedRank,assumedLen)
external :: notData
- !ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
+ !WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
real, value :: notADummy
value :: notData
!ERROR: VALUE attribute may not apply to an assumed-size array
diff --git a/flang/test/Semantics/resolve58.f90 b/flang/test/Semantics/resolve58.f90
index 2e42eb157f5b50..7686de4898404d 100644
--- a/flang/test/Semantics/resolve58.f90
+++ b/flang/test/Semantics/resolve58.f90
@@ -69,12 +69,12 @@ subroutine s6()
!ERROR: Implied-shape array 'local1' must be a named constant or a dummy argument
real, dimension (*) :: local1
- !ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
+ !WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
real, intent(in) :: local2
- !ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
+ !WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
procedure(), intent(in) :: p1
- !ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
+ !WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
real, optional :: local3
- !ERROR: Only a dummy argument may have an INTENT, VALUE, or OPTIONAL attribute
+ !WARNING: Only a dummy argument should have an INTENT, VALUE, or OPTIONAL attribute
procedure(), optional :: p2
end subroutine
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All builds and tests correctly and looks good.
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.