Skip to content

[flang] Improve two coarray error messages #129597

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

Merged
merged 1 commit into from
Mar 3, 2025
Merged

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Mar 3, 2025

Two messages that complain about local variables mention that they don't have the SAVE attribute; in both cases, it would be okay if they were ALLOCATABLE instead. Clarify the messages.

Two messages that complain about local variables mention that
they don't have the SAVE attribute; in both cases, it would be
okay if they were ALLOCATABLE instead.  Clarify the messages.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Mar 3, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

Two messages that complain about local variables mention that they don't have the SAVE attribute; in both cases, it would be okay if they were ALLOCATABLE instead. Clarify the messages.


Full diff: https://github.com/llvm/llvm-project/pull/129597.diff

3 Files Affected:

  • (modified) flang/lib/Semantics/check-declarations.cpp (+3-2)
  • (modified) flang/test/Semantics/coarrays02.f90 (+3-3)
  • (modified) flang/test/Semantics/init01.f90 (+1-1)
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index c30c15a290b84..d26485d359132 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -731,7 +731,8 @@ void CheckHelper::CheckObjectEntity(
           symbol.name(), commonBlock->name());
     } else if (isLocalVariable && !IsAllocatableOrPointer(symbol) &&
         !IsSaved(symbol)) {
-      messages_.Say("Local coarray must have the SAVE attribute"_err_en_US);
+      messages_.Say(
+          "Local coarray must have the SAVE or ALLOCATABLE attribute"_err_en_US);
     }
     for (int j{0}; j < corank; ++j) {
       if (auto lcbv{evaluate::ToInt64(evaluate::Fold(
@@ -980,7 +981,7 @@ void CheckHelper::CheckObjectEntity(
               symbol.name(), badPotential.BuildResultDesignatorName());
         } else if (isUnsavedLocal) { // F'2023 C826
           SayWithDeclaration(*badPotential,
-              "Local variable '%s' without the SAVE attribute may not have a coarray potential subobject component '%s'"_err_en_US,
+              "Local variable '%s' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%s'"_err_en_US,
               symbol.name(), badPotential.BuildResultDesignatorName());
         } else {
           DIE("caught unexpected bad coarray potential component");
diff --git a/flang/test/Semantics/coarrays02.f90 b/flang/test/Semantics/coarrays02.f90
index e52f3e3ef3a40..a9f4958204936 100644
--- a/flang/test/Semantics/coarrays02.f90
+++ b/flang/test/Semantics/coarrays02.f90
@@ -6,7 +6,7 @@ module m
 program main
   use iso_fortran_env
   !ERROR: Coarray 'namedconst' may not be a named constant
-  !ERROR: Local coarray must have the SAVE attribute
+  !ERROR: Local coarray must have the SAVE or ALLOCATABLE attribute
   integer, parameter :: namedConst = 123
   codimension namedConst[*]
   !ERROR: Coarray 'coarr1' may not be in COMMON block '//'
@@ -22,7 +22,7 @@ program main
 function func1()
   !ERROR: Function result may not be a coarray
   integer :: func1[*]
-  !ERROR: Local coarray must have the SAVE attribute
+  !ERROR: Local coarray must have the SAVE or ALLOCATABLE attribute
   integer :: local[*]
   integer, save :: saved[*] ! ok
   integer :: inited[*] = 1 ! ok
@@ -45,6 +45,6 @@ function func2()
   type(t), pointer :: ptr
   !ERROR: Coarray 'coarr' may not have a coarray potential component '%comp'
   type(t), save :: coarr[*]
-  !ERROR: Local variable 'local' without the SAVE attribute may not have a coarray potential subobject component '%comp'
+  !ERROR: Local variable 'local' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%comp'
   type(t) :: local
 end
diff --git a/flang/test/Semantics/init01.f90 b/flang/test/Semantics/init01.f90
index a1313e7c234d5..a34930e6b5be9 100644
--- a/flang/test/Semantics/init01.f90
+++ b/flang/test/Semantics/init01.f90
@@ -18,7 +18,7 @@ subroutine objectpointers(j)
   end type
   type(t1), target, save :: o1
   type(t1), save :: o2
-!ERROR: Local variable 'o3' without the SAVE attribute may not have a coarray potential subobject component '%c2'
+!ERROR: Local variable 'o3' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%c2'
   type(t1), target :: o3
 !ERROR: An initial data target may not be a reference to an ALLOCATABLE 'x1'
   real, pointer :: p1 => x1

@klausler klausler merged commit f6e8366 into llvm:main Mar 3, 2025
12 of 13 checks passed
@klausler klausler deleted the fix-msg branch March 3, 2025 22:47
jph-13 pushed a commit to jph-13/llvm-project that referenced this pull request Mar 21, 2025
Two messages that complain about local variables mention that they don't
have the SAVE attribute; in both cases, it would be okay if they were
ALLOCATABLE instead. Clarify the messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants