forked from OSchip/llvm-project
[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
This commit is contained in:
parent
28d718602a
commit
2985d5623c
|
@ -237,9 +237,14 @@ void CheckHelper::Check(const Symbol &symbol) {
|
||||||
}
|
}
|
||||||
if (InPure()) {
|
if (InPure()) {
|
||||||
if (IsSaved(symbol)) {
|
if (IsSaved(symbol)) {
|
||||||
|
if (IsInitialized(symbol)) {
|
||||||
|
messages_.Say(
|
||||||
|
"A pure subprogram may not initialize a variable"_err_en_US);
|
||||||
|
} else {
|
||||||
messages_.Say(
|
messages_.Say(
|
||||||
"A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
|
"A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (symbol.attrs().test(Attr::VOLATILE)) {
|
if (symbol.attrs().test(Attr::VOLATILE)) {
|
||||||
messages_.Say(
|
messages_.Say(
|
||||||
"A pure subprogram may not have a variable with the VOLATILE attribute"_err_en_US);
|
"A pure subprogram may not have a variable with the VOLATILE attribute"_err_en_US);
|
||||||
|
|
|
@ -85,9 +85,9 @@ module m
|
||||||
pure subroutine s05 ! C1589
|
pure subroutine s05 ! C1589
|
||||||
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
||||||
real, save :: v1
|
real, save :: v1
|
||||||
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
!ERROR: A pure subprogram may not initialize a variable
|
||||||
real :: v2 = 0.
|
real :: v2 = 0.
|
||||||
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
!ERROR: A pure subprogram may not initialize a variable
|
||||||
real :: v3
|
real :: v3
|
||||||
data v3/0./
|
data v3/0./
|
||||||
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
||||||
|
@ -97,7 +97,7 @@ module m
|
||||||
block
|
block
|
||||||
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
||||||
real, save :: v5
|
real, save :: v5
|
||||||
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
|
!ERROR: A pure subprogram may not initialize a variable
|
||||||
real :: v6 = 0.
|
real :: v6 = 0.
|
||||||
end block
|
end block
|
||||||
end subroutine
|
end subroutine
|
||||||
|
|
Loading…
Reference in New Issue