[flang-commits] [flang] [flang] Allow use of COMMON in PURE (PR #76741)
via flang-commits
flang-commits at lists.llvm.org
Tue Jan 2 10:46:25 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/76741.diff
2 Files Affected:
- (modified) flang/lib/Semantics/check-declarations.cpp (+7-9)
- (modified) flang/test/Semantics/call10.f90 (-4)
``````````diff
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..dab2f874a9a953 100644
--- a/flang/test/Semantics/call10.f90
+++ b/flang/test/Semantics/call10.f90
@@ -109,10 +109,6 @@ 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/76741
More information about the flang-commits
mailing list