Bug 113979 - [11/12/13/14 regression] bogus error on allocator for array type with Dynamic_Predicate
Summary: [11/12/13/14 regression] bogus error on allocator for array type with Dynamic...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: ada (show other bugs)
Version: 14.0
: P4 normal
Target Milestone: 11.5
Assignee: Eric Botcazou
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-18 14:31 UTC by simon
Modified: 2024-03-07 14:28 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-02-19 00:00:00


Attachments
Reproducer (307 bytes, application/zip)
2024-02-18 14:31 UTC, simon
Details

Note You need to log in before you can comment on or make changes to this bug.
Description simon 2024-02-18 14:31:12 UTC
Created attachment 57455 [details]
Reproducer

This error is present in GCC 11/12/13/14 -- can’t tell about GCC 10.

The error doesn’t occur without -gnata.

--

$ /opt/gcc-14.0.1-20240114-x86_64/bin/gnatmake alloc2.adb -gnatwa -gnatl -f -gnata
gcc -c -gnatwa -gnatl -gnata alloc2.adb

GNAT 14.0.1 20240114 (experimental)
Copyright 1992-2023, Free Software Foundation, Inc.

Compiling: alloc2.adb
Source file time stamp: 2024-02-18 14:27:29
Compiled at: 2024-02-18 14:28:05

     1. procedure Alloc2 is
     2.    type Grid is array (Positive range <>, Positive range <>) of Integer with
     3.       Dynamic_Predicate => Grid'First (1) = 1 and then Grid'First (2) = 1;
     4.
     5.    type Grid_Ptr is access Grid;
     6.
     7.    Data : Grid_Ptr := new Grid (1 .. 10, 1 .. 20);
                              |
        >>> error: invalid use of subtype mark in expression or call

     8. begin -- Alloc2
     9.    null;
    10. end Alloc2;

 10 lines: 1 error
gnatmake: "alloc2.adb" compilation error
Comment 1 Eric Botcazou 2024-02-19 12:17:20 UTC
Presumably something goes wrong during the expansion of the check.
Comment 2 Eric Botcazou 2024-02-19 12:17:46 UTC
I'll have a look.
Comment 3 GCC Commits 2024-03-07 14:08:43 UTC
The master branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>:

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

commit r14-9361-ge71a4e81729516eed8782a255ff37617e6fd4b69
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,
            call Apply_Predicate_Check on the resulting access value if needed.
    
    gcc/testsuite/
            * gnat.dg/predicate15.adb: New test.
Comment 4 GCC Commits 2024-03-07 14:18:47 UTC
The releases/gcc-13 branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>:

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.
Comment 5 GCC Commits 2024-03-07 14:22:06 UTC
The releases/gcc-12 branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>:

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

commit r12-10197-gf9e1d7aa8b4f0b8afff1de59fcadf1db0244b4e1
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.
Comment 6 GCC Commits 2024-03-07 14:27:23 UTC
The releases/gcc-11 branch has been updated by Eric Botcazou <ebotcazou@gcc.gnu.org>:

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

commit r11-11272-gb26501b6e310345ad9f6423b3f8b9df178c5e7d9
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.
Comment 7 Eric Botcazou 2024-03-07 14:28:49 UTC
Fixed on mainline and all branches.