public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-8409] Fix bogus error on allocator for array type with Dynamic_Predicate
Date: Thu,  7 Mar 2024 14:18:46 +0000 (GMT)	[thread overview]
Message-ID: <20240307141846.4B8D83857C65@sourceware.org> (raw)

https://gcc.gnu.org/g:0e591e6f27a20c26672ea8c0550a6ef673c1fccf

commit r13-8409-g0e591e6f27a20c26672ea8c0550a6ef673c1fccf
Author: Eric Botcazou <ebotcazou@adacore.com>
Date:   Thu Mar 7 15:05:54 2024 +0100

    Fix bogus error on allocator for array type with Dynamic_Predicate
    
    This is a regression present on all active branches: the compiler gives
    a bogus error on an allocator for an unconstrained array type declared
    with a Dynamic_Predicate because Apply_Predicate_Check is invoked directly
    on a subtype reference, which it cannot handle.
    
    This moves the check to the resulting access value (after dereference) like
    in Expand_Allocator_Expression.
    
    gcc/ada/
            PR ada/113979
            * exp_ch4.adb (Expand_N_Allocator): In the subtype indication case,
            remove call to Apply_Predicate_Check.
    
    gcc/testsuite/
            * gnat.dg/predicate15.adb: New test.

Diff:
---
 gcc/ada/exp_ch4.adb                   |  2 --
 gcc/testsuite/gnat.dg/predicate15.adb | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb
index 8442de6f90c..5cb6ee25702 100644
--- a/gcc/ada/exp_ch4.adb
+++ b/gcc/ada/exp_ch4.adb
@@ -4785,8 +4785,6 @@ package body Exp_Ch4 is
          if Is_Array_Type (Dtyp) and then not No_Initialization (N) then
             Apply_Constraint_Check (Expression (N), Dtyp, No_Sliding => True);
 
-            Apply_Predicate_Check (Expression (N), Dtyp);
-
             if Nkind (Expression (N)) = N_Raise_Constraint_Error then
                Rewrite (N, New_Copy (Expression (N)));
                Set_Etype (N, PtrT);
diff --git a/gcc/testsuite/gnat.dg/predicate15.adb b/gcc/testsuite/gnat.dg/predicate15.adb
new file mode 100644
index 00000000000..cf9e1d9e17f
--- /dev/null
+++ b/gcc/testsuite/gnat.dg/predicate15.adb
@@ -0,0 +1,15 @@
+-- { dg-do compile }
+-- { dg-options "-gnata" }
+
+procedure Predicate15 is
+
+   type Grid is array (Positive range <>) of Integer with
+      Dynamic_Predicate => Grid'First = 1;
+
+   type Grid_Ptr is access Grid;
+
+   Data : Grid_Ptr := new Grid (1 .. 10);
+
+begin
+   null;
+end;

                 reply	other threads:[~2024-03-07 14:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240307141846.4B8D83857C65@sourceware.org \
    --to=ebotcazou@gcc.gnu.org \
    --cc=gcc-cvs@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).