Skip to content

Commit f6e8366

Browse files
authored
[flang] Improve two coarray error messages (#129597)
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.
1 parent 79a25e1 commit f6e8366

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

flang/lib/Semantics/check-declarations.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ void CheckHelper::CheckObjectEntity(
731731
symbol.name(), commonBlock->name());
732732
} else if (isLocalVariable && !IsAllocatableOrPointer(symbol) &&
733733
!IsSaved(symbol)) {
734-
messages_.Say("Local coarray must have the SAVE attribute"_err_en_US);
734+
messages_.Say(
735+
"Local coarray must have the SAVE or ALLOCATABLE attribute"_err_en_US);
735736
}
736737
for (int j{0}; j < corank; ++j) {
737738
if (auto lcbv{evaluate::ToInt64(evaluate::Fold(
@@ -980,7 +981,7 @@ void CheckHelper::CheckObjectEntity(
980981
symbol.name(), badPotential.BuildResultDesignatorName());
981982
} else if (isUnsavedLocal) { // F'2023 C826
982983
SayWithDeclaration(*badPotential,
983-
"Local variable '%s' without the SAVE attribute may not have a coarray potential subobject component '%s'"_err_en_US,
984+
"Local variable '%s' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%s'"_err_en_US,
984985
symbol.name(), badPotential.BuildResultDesignatorName());
985986
} else {
986987
DIE("caught unexpected bad coarray potential component");

flang/test/Semantics/coarrays02.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module m
66
program main
77
use iso_fortran_env
88
!ERROR: Coarray 'namedconst' may not be a named constant
9-
!ERROR: Local coarray must have the SAVE attribute
9+
!ERROR: Local coarray must have the SAVE or ALLOCATABLE attribute
1010
integer, parameter :: namedConst = 123
1111
codimension namedConst[*]
1212
!ERROR: Coarray 'coarr1' may not be in COMMON block '//'
@@ -22,7 +22,7 @@ program main
2222
function func1()
2323
!ERROR: Function result may not be a coarray
2424
integer :: func1[*]
25-
!ERROR: Local coarray must have the SAVE attribute
25+
!ERROR: Local coarray must have the SAVE or ALLOCATABLE attribute
2626
integer :: local[*]
2727
integer, save :: saved[*] ! ok
2828
integer :: inited[*] = 1 ! ok
@@ -45,6 +45,6 @@ function func2()
4545
type(t), pointer :: ptr
4646
!ERROR: Coarray 'coarr' may not have a coarray potential component '%comp'
4747
type(t), save :: coarr[*]
48-
!ERROR: Local variable 'local' without the SAVE attribute may not have a coarray potential subobject component '%comp'
48+
!ERROR: Local variable 'local' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%comp'
4949
type(t) :: local
5050
end

flang/test/Semantics/init01.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ subroutine objectpointers(j)
1818
end type
1919
type(t1), target, save :: o1
2020
type(t1), save :: o2
21-
!ERROR: Local variable 'o3' without the SAVE attribute may not have a coarray potential subobject component '%c2'
21+
!ERROR: Local variable 'o3' without the SAVE or ALLOCATABLE attribute may not have a coarray potential subobject component '%c2'
2222
type(t1), target :: o3
2323
!ERROR: An initial data target may not be a reference to an ALLOCATABLE 'x1'
2424
real, pointer :: p1 => x1

0 commit comments

Comments
 (0)