[flang-commits] [flang] [flang] Add portability warning for F'2008 feature (PR #77526)
via flang-commits
flang-commits at lists.llvm.org
Tue Jan 9 13:34:45 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
Using the VALUE attribute for assumed-length CHARACTER dummy arguments became standard in F'2008 but still lacks widespread implementation; emit a portability warning when they are enabled.
Resolves llvm-test-suite/Fortran/gfortran/regression/value_5.f90.
---
Full diff: https://github.com/llvm/llvm-project/pull/77526.diff
3 Files Affected:
- (modified) flang/docs/Extensions.md (+3)
- (modified) flang/lib/Semantics/check-declarations.cpp (+6)
- (modified) flang/test/Semantics/call14.f90 (+4-2)
``````````diff
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index 16eb67f2e27c81..c1b64c088fa228 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -451,6 +451,9 @@ end
* A `SEQUENCE` derived type is required (F'2023 C745) to have
at least one component. No compiler enforces this constraint;
this compiler emits a warning.
+* Many compilers disallow a `VALUE` assumed-length character dummy
+ argument, which has been standard since F'2008.
+ We accept this usage with an optional portability warning.
## Behavior in cases where the standard is ambiguous or indefinite
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 777e6a9f23fbf8..14dd60fc37d2f1 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -572,6 +572,12 @@ void CheckHelper::CheckValue(
messages_.Say(
"VALUE attribute may not apply to an assumed-rank array"_err_en_US);
}
+ if (context_.ShouldWarn(common::UsageWarning::Portability) &&
+ IsAssumedLengthCharacter(symbol)) {
+ // F'2008 feature not widely implemented
+ messages_.Say(
+ "VALUE attribute on assumed-length CHARACTER may not be portable"_port_en_US);
+ }
}
void CheckHelper::CheckAssumedTypeEntity( // C709
diff --git a/flang/test/Semantics/call14.f90 b/flang/test/Semantics/call14.f90
index da273050b6f3a9..042243b5605938 100644
--- a/flang/test/Semantics/call14.f90
+++ b/flang/test/Semantics/call14.f90
@@ -1,4 +1,4 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1
+! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic
! Test 8.5.18 constraints on the VALUE attribute
module m
@@ -7,7 +7,7 @@ module m
end type
contains
!ERROR: VALUE attribute may apply only to a dummy data object
- subroutine C863(notData,assumedSize,coarray,coarrayComponent,assumedRank)
+ subroutine C863(notData,assumedSize,coarray,coarrayComponent,assumedRank,assumedLen)
external :: notData
!ERROR: VALUE attribute may apply only to a dummy argument
real, value :: notADummy
@@ -20,6 +20,8 @@ subroutine C863(notData,assumedSize,coarray,coarrayComponent,assumedRank)
type(hasCoarray), value :: coarrayComponent
!ERROR: VALUE attribute may not apply to an assumed-rank array
real, value :: assumedRank(..)
+ !PORTABILITY: VALUE attribute on assumed-length CHARACTER may not be portable
+ character(*), value :: assumedLen
end subroutine
subroutine C864(allocatable, inout, out, pointer, volatile)
!ERROR: VALUE attribute may not apply to an ALLOCATABLE
``````````
</details>
https://github.com/llvm/llvm-project/pull/77526
More information about the flang-commits
mailing list