[flang-commits] [flang] [flang] Recognize SIMPLE prefix in purity checks (PR #232175)

Šárka Holendová via flang-commits flang-commits at lists.llvm.org
Wed Oct 14 21:28:18 PDT 2026


https://github.com/mlir-maiden created https://github.com/llvm/llvm-project/pull/232175

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

>From 4b4435d649d6e0e7e1ecc825a25c515e8a20b127 Mon Sep 17 00:00:00 2001
From: Sarka Holendova <sarka.holendova at gmail.com>
Date: Wed, 14 Oct 2026 21:21:29 -0700
Subject: [PATCH] [flang] Recognize SIMPLE prefix in purity checks

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
---
 flang/lib/Semantics/check-purity.cpp          |  1 +
 flang/test/Semantics/simple-purity-checks.f90 | 28 +++++++++++++++++++
 .../Semantics/simple-purity-image-control.f90 |  7 +++++
 3 files changed, 36 insertions(+)
 create mode 100644 flang/test/Semantics/simple-purity-checks.f90
 create mode 100644 flang/test/Semantics/simple-purity-image-control.f90

diff --git a/flang/lib/Semantics/check-purity.cpp b/flang/lib/Semantics/check-purity.cpp
index b327282f390e51..59bf48aba93d23 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 00000000000000..92ba1e3c5e3b03
--- /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 00000000000000..c5b9390b16002d
--- /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



More information about the flang-commits mailing list