diff options
author | Peter Klausler <35819229+klausler@users.noreply.github.com> | 2024-01-15 09:20:20 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 09:20:20 -0800 |
commit | 6d4c88786aa503f803a6ec881e66fe1e1f38f6d8 (patch) | |
tree | 369d6d54524a4c087f0f69fa8d0b4ee63f42826c | |
parent | 01dbc5da336de0dc2dbba31900fbc9572f39443d (diff) | |
download | llvm-6d4c88786aa503f803a6ec881e66fe1e1f38f6d8.zip llvm-6d4c88786aa503f803a6ec881e66fe1e1f38f6d8.tar.gz llvm-6d4c88786aa503f803a6ec881e66fe1e1f38f6d8.tar.bz2 |
[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.
-rw-r--r-- | flang/lib/Semantics/check-declarations.cpp | 16 | ||||
-rw-r--r-- | flang/test/Semantics/call10.f90 | 2 |
2 files changed, 7 insertions, 11 deletions
diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index 777e6a9..93acb60 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 2a840e1..b1f3528 100644 --- a/flang/test/Semantics/call10.f90 +++ b/flang/test/Semantics/call10.f90 @@ -109,10 +109,8 @@ module m !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 |