[flang-commits] [flang] 6d4c887 - [flang] Allow use of COMMON in PURE (#76741)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 15 09:20:25 PST 2024
Author: Peter Klausler
Date: 2024-01-15T09:20:20-08:00
New Revision: 6d4c88786aa503f803a6ec881e66fe1e1f38f6d8
URL: https://github.com/llvm/llvm-project/commit/6d4c88786aa503f803a6ec881e66fe1e1f38f6d8
DIFF: https://github.com/llvm/llvm-project/commit/6d4c88786aa503f803a6ec881e66fe1e1f38f6d8.diff
LOG: [flang] Allow use of COMMON in PURE (#76741)
Although COMMON variables implicitly have the SAVE attribute, and
variables with the SAVE attribute are generally disallowed in PURE
subprograms, we must allow the use of COMMON in PURE as an exception.
F'2023 constraint C1598 applies only to local variables.
Added:
Modified:
flang/lib/Semantics/check-declarations.cpp
flang/test/Semantics/call10.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp
index 777e6a9f23fbf8..93acb603297a47 100644
--- a/flang/lib/Semantics/check-declarations.cpp
+++ b/flang/lib/Semantics/check-declarations.cpp
@@ -317,15 +317,13 @@ void CheckHelper::Check(const Symbol &symbol) {
// are not pertinent to the characteristics of the procedure.
// Restrictions on entities in pure procedure interfaces don't need
// enforcement.
- } else {
- if (IsSaved(symbol)) {
- if (IsInitialized(symbol)) {
- messages_.Say(
- "A pure subprogram may not initialize a variable"_err_en_US);
- } else {
- messages_.Say(
- "A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
- }
+ } else if (!FindCommonBlockContaining(symbol) && IsSaved(symbol)) {
+ if (IsInitialized(symbol)) {
+ messages_.Say(
+ "A pure subprogram may not initialize a variable"_err_en_US);
+ } else {
+ messages_.Say(
+ "A pure subprogram may not have a variable with the SAVE attribute"_err_en_US);
}
}
if (symbol.attrs().test(Attr::VOLATILE) &&
diff --git a/flang/test/Semantics/call10.f90 b/flang/test/Semantics/call10.f90
index 2a840e111e2ab2..b1f35282274978 100644
--- a/flang/test/Semantics/call10.f90
+++ b/flang/test/Semantics/call10.f90
@@ -109,10 +109,8 @@ pure subroutine s05 ! C1589
!ERROR: A pure subprogram may not initialize a variable
real :: v3
data v3/0./
- !ERROR: A pure subprogram may not have a variable with the SAVE attribute
real :: v4
common /blk/ v4
- save /blk/
block
!ERROR: A pure subprogram may not have a variable with the SAVE attribute
real, save :: v5
More information about the flang-commits
mailing list