[flang-commits] [flang] [flang] Add portability warning for F'2008 feature (PR #77526)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Jan 9 13:34:14 PST 2024


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/77526

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.

>From d8ee255f78c8ea0fe02382b7b1c851daba2aa40f Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 9 Jan 2024 13:31:56 -0800
Subject: [PATCH] [flang] Add portability warning for F'2008 feature

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.
---
 flang/docs/Extensions.md                   | 3 +++
 flang/lib/Semantics/check-declarations.cpp | 6 ++++++
 flang/test/Semantics/call14.f90            | 6 ++++--
 3 files changed, 13 insertions(+), 2 deletions(-)

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



More information about the flang-commits mailing list