https://gcc.gnu.org/g:a8329c92a4f0554a13eaa75b1323d4ba4dcdd4fd

commit r17-6587-ga8329c92a4f0554a13eaa75b1323d4ba4dcdd4fd
Author: Eric Botcazou <[email protected]>
Date:   Mon Nov 23 09:28:13 2026 +0100

    Ada: Fix pure library procedure with limited parameters miscategorized
    
    The problem is that a pragma Pure present either on the containing library
    package or on a library subprogram itself does not necessarily imply that
    the Is_Pure flag is set on the subprogram entity, the discrepancy coming
    from the Sem_Util.Check_Function_With_Address_Parameter routine.  This is
    a minimal fix because it's really a corner case.
    
    gcc/ada/
            PR ada/108610
            * sem_cat.adb (Get_Categorization): Always return Pure if a pragma
            Pure is present on the unit.
    
    gcc/testsuite/
            * gnat.dg/pure_subp_body2a.adb: New test.
            * gnat.dg/pure_subp_body2b.adb: New helper subprogram.
            * gnat.dg/pure_subp_body2_pkg.ads: New helper package.

Diff:
---
 gcc/ada/sem_cat.adb                           | 5 ++---
 gcc/testsuite/gnat.dg/pure_subp_body2_pkg.ads | 4 ++++
 gcc/testsuite/gnat.dg/pure_subp_body2a.adb    | 9 +++++++++
 gcc/testsuite/gnat.dg/pure_subp_body2b.adb    | 7 +++++++
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/gcc/ada/sem_cat.adb b/gcc/ada/sem_cat.adb
index 7979c80ced04..b29fb2ced4fc 100644
--- a/gcc/ada/sem_cat.adb
+++ b/gcc/ada/sem_cat.adb
@@ -158,9 +158,8 @@ package body Sem_Cat is
 
          --  Ignore Pure specification if set by pragma Pure_Function
 
-         if Is_Pure (E)
-           and then not
-            (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E))
+         if Has_Pragma_Pure (E)
+           or else (Is_Pure (E) and then not Has_Pragma_Pure_Function (E))
          then
             return Pure;
 
diff --git a/gcc/testsuite/gnat.dg/pure_subp_body2_pkg.ads 
b/gcc/testsuite/gnat.dg/pure_subp_body2_pkg.ads
new file mode 100644
index 000000000000..a16f46738d1d
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/pure_subp_body2_pkg.ads
@@ -0,0 +1,4 @@
+package Pure_Subp_Body2_Pkg is
+  pragma Pure;  
+  type T is limited null record;
+end Pure_Subp_Body2_Pkg;
diff --git a/gcc/testsuite/gnat.dg/pure_subp_body2a.adb 
b/gcc/testsuite/gnat.dg/pure_subp_body2a.adb
new file mode 100644
index 000000000000..3cf5e7b6e9f7
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/pure_subp_body2a.adb
@@ -0,0 +1,9 @@
+-- { dg-do compile }
+
+with Pure_Subp_Body2b;
+
+procedure Pure_Subp_Body2a is
+  pragma Pure;
+begin
+  null;
+end;
diff --git a/gcc/testsuite/gnat.dg/pure_subp_body2b.adb 
b/gcc/testsuite/gnat.dg/pure_subp_body2b.adb
new file mode 100644
index 000000000000..dd4d269c2d36
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/pure_subp_body2b.adb
@@ -0,0 +1,7 @@
+with Pure_Subp_Body2_Pkg;
+
+procedure Pure_Subp_Body2b (X : Pure_Subp_Body2_Pkg.T) is
+  pragma Pure;
+begin
+  null;
+end;

Reply via email to