From: Eric Botcazou Date: Thu, 7 Mar 2024 14:05:54 +0000 (+0100) Subject: Fix bogus error on allocator for array type with Dynamic_Predicate X-Git-Tag: releases/gcc-12.4.0~369 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9e1d7aa8b4f0b8afff1de59fcadf1db0244b4e1;p=thirdparty%2Fgcc.git 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 --git a/gcc/ada/exp_ch4.adb b/gcc/ada/exp_ch4.adb index 2506c67e9367..6429c6e9d699 100644 --- a/gcc/ada/exp_ch4.adb +++ b/gcc/ada/exp_ch4.adb @@ -4823,8 +4823,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 000000000000..cf9e1d9e17ff --- /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;