public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sbelmont700 at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug ada/108610] New: Pure library procedures with limited parameters miscategorized
Date: Tue, 31 Jan 2023 02:13:35 +0000	[thread overview]
Message-ID: <bug-108610-4@http.gcc.gnu.org/bugzilla/> (raw)

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 <gccadmin@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

             reply	other threads:[~2023-01-31  2:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-31  2:13 sbelmont700 at gmail dot com [this message]
2023-05-11 16:01 ` [Bug ada/108610] pure " ebotcazou at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108610-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).