https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108610
Bug ID: 108610 Summary: Pure library procedures with limited parameters miscategorized Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ada Assignee: unassigned at gcc dot gnu.org Reporter: sbelmont700 at gmail dot com CC: dkm at gcc dot gnu.org Target Milestone: --- The following (seemingly) legal code is rejected with a categorization error, despite the elaboration pragma on B and apparently not violating any of the requirements of 10.2.1: package A is pragma Pure; type T is limited null record; end A; with A; procedure B (x : A.T) is pragma Pure; begin null; end B; with B; package C is pragma Pure; end C; $gnatmake -f c.ads gcc -c c.ads c.ads:1:06: error: cannot depend on "B" (wrong categorization) c.ads:1:06: error: pure unit cannot depend on non-pure unit gnatmake: "c.ads" compilation error Presumably, gnat considers B as impure to implement the exception to the permission in 10.2.1~18/3 (subprograms with limited parameters cannot have their results reused), so this might also apply to parameters that take System.Address, etc, or also in reverse (i.e. pure units incorrectly being allowed to with non-pure units that the compiler has determined can be optimized). The version of GCC was built from the following commit: commit 607f278a3546fe6b91a881318db85d7a0dfdacd9 (HEAD -> master, origin/trunk, origin/master, origin/HEAD) Author: GCC Administrator <gccad...@gcc.gnu.org> Date: Tue Jan 24 00:17:23 2023 +0000 Daily bump. With the following configuration $gnatmake -v GNATMAKE 13.0.1 20230124 (experimental) Copyright (C) 1992-2023, Free Software Foundation, Inc. try "gnatmake --help" for more information. $gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/home/sb/src/gcc/bin/libexec/gcc/x86_64-pc-linux-gnu/13.0.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../src/configure --prefix=/home/sb/src/gcc/bin --enable-languages=c,c++,ada --disable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.1 20230124 (experimental) (GCC) The following patch appears to mitigate the issue (within the Get_Categorization subprogram, only consider the entity as pure if it has been explicitly declared Pure) and passed the test suite, but i wouldn't presume to imply its accuracy. diff --git a/gcc/ada/sem_cat.adb b/gcc/ada/sem_cat.adb index 5398153a35d..ac276eb5443 100644 --- a/gcc/ada/sem_cat.adb +++ b/gcc/ada/sem_cat.adb @@ -160,7 +160,7 @@ package body Sem_Cat is -- Ignore Pure specification if set by pragma Pure_Function - if Is_Pure (E) + if Has_Pragma_Pure (E) and then not (Has_Pragma_Pure_Function (E) and not Has_Pragma_Pure (E)) then Thanks