[flang-commits] [flang] [flang] Recognize SIMPLE prefix in purity checks (PR #232175)
via flang-commits
flang-commits at lists.llvm.org
Wed Oct 14 21:28:53 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Šárka Holendová (mlir-maiden)
<details>
<summary>Changes</summary>
Treat `SIMPLE` as a `PURE` prefix in `PurityChecker::HasPurePrefix`, as required by F2023 15.8 p2.
Add regression tests for image control statements (C15109) and internal subprogram purity (C15102).
Fixes #<!-- -->231353
---
Full diff: https://github.com/llvm/llvm-project/pull/232175.diff
3 Files Affected:
- (modified) flang/lib/Semantics/check-purity.cpp (+1)
- (added) flang/test/Semantics/simple-purity-checks.f90 (+28)
- (added) flang/test/Semantics/simple-purity-image-control.f90 (+7)
``````````diff
diff --git a/flang/lib/Semantics/check-purity.cpp b/flang/lib/Semantics/check-purity.cpp
index b327282f390e5..59bf48aba93d2 100644
--- a/flang/lib/Semantics/check-purity.cpp
+++ b/flang/lib/Semantics/check-purity.cpp
@@ -48,6 +48,7 @@ bool PurityChecker::HasPurePrefix(
if (std::holds_alternative<parser::PrefixSpec::Impure>(prefix.u)) {
return false;
} else if (std::holds_alternative<parser::PrefixSpec::Pure>(prefix.u) ||
+ std::holds_alternative<parser::PrefixSpec::Simple>(prefix.u) ||
std::holds_alternative<parser::PrefixSpec::Elemental>(prefix.u)) {
result = true;
}
diff --git a/flang/test/Semantics/simple-purity-checks.f90 b/flang/test/Semantics/simple-purity-checks.f90
new file mode 100644
index 0000000000000..92ba1e3c5e3b0
--- /dev/null
+++ b/flang/test/Semantics/simple-purity-checks.f90
@@ -0,0 +1,28 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+
+! F2023 15.8 p2: A SIMPLE procedure is also PURE.
+! F2023 C15102: An internal subprogram of a pure subprogram must be pure
+
+! A SIMPLE subprogram may not contain an impure internal subprogram
+! C15113 additionally requires the internal subprogram to be SIMPLE
+simple subroutine s(x)
+ integer, intent(inout) :: x
+ x = x + 1
+contains
+ !ERROR: An internal subprogram of a pure subprogram must also be pure
+ subroutine inner(y)
+ integer, intent(inout) :: y
+ y = y + 1
+ end subroutine
+end subroutine
+
+! A SIMPLE internal subprogram satisfies the PURE requirement
+pure subroutine t(x)
+ integer, intent(inout) :: x
+ call inner(x)
+contains
+ simple subroutine inner(y)
+ integer, intent(inout) :: y
+ y = y + 1
+ end subroutine
+end subroutine
\ No newline at end of file
diff --git a/flang/test/Semantics/simple-purity-image-control.f90 b/flang/test/Semantics/simple-purity-image-control.f90
new file mode 100644
index 0000000000000..c5b9390b16002
--- /dev/null
+++ b/flang/test/Semantics/simple-purity-image-control.f90
@@ -0,0 +1,7 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1 -fcoarray
+
+! F2023 15.8 p2: A SIMPLE procedure is also PURE
+simple subroutine s()
+ !ERROR: An image control statement may not appear in a pure subprogram
+ sync all
+end subroutine
\ No newline at end of file
``````````
</details>
https://github.com/llvm/llvm-project/pull/232175
More information about the flang-commits
mailing list