Skip to content

Commit 2985d56

Browse files
committed
[flang] Improve error message (initialized variable in pure subprogram)
When variable with the SAVE attribute appears in a pure subprogram, emit a more specialized error message if the SAVE attribute was acquired from static initialization. Differential Revision: https://reviews.llvm.org/D117699
1 parent 28d7186 commit 2985d56

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

flang/lib/Semantics/check-declarations.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,13 @@ void CheckHelper::Check(const Symbol &symbol) {
237237
}
238238
if (InPure()) {
239239
if (IsSaved(symbol)) {
240-
messages_.Say(
241-
"A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
240+
if (IsInitialized(symbol)) {
241+
messages_.Say(
242+
"A pure subprogram may not initialize a variable"_err_en_US);
243+
} else {
244+
messages_.Say(
245+
"A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
246+
}
242247
}
243248
if (symbol.attrs().test(Attr::VOLATILE)) {
244249
messages_.Say(

flang/test/Semantics/call10.f90

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ pure subroutine s04(a) ! C1588
8585
pure subroutine s05 ! C1589
8686
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
8787
real, save :: v1
88-
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
88+
!ERROR: A pure subprogram may not initialize a variable
8989
real :: v2 = 0.
90-
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
90+
!ERROR: A pure subprogram may not initialize a variable
9191
real :: v3
9292
data v3/0./
9393
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
@@ -97,7 +97,7 @@ pure subroutine s05 ! C1589
9797
block
9898
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
9999
real, save :: v5
100-
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
100+
!ERROR: A pure subprogram may not initialize a variable
101101
real :: v6 = 0.
102102
end block
103103
end subroutine

0 commit comments

Comments
 (0)