From: Eric Botcazou <botcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Fix crash on array component with nonstandard index type
Date: Fri, 11 Sep 2020 11:23:17 +0200 [thread overview]
Message-ID: <15239409.lD0NLk8hKn@fomalhaut> (raw)
[-- Attachment #1: Type: text/plain, Size: 775 bytes --]
This is a regression present on mainline, 10 and 9 branches: the compiler goes
into an infinite recursion eventually exhausting the stack for the declaration
of a discriminated record type with an array component having a discriminant
as bound and an index type that is an enumeration type with a non-standard
representation clause.
Tested on x86_64-suse-linux, applied on the mainline, 10 and 9 branches.
2020-09-11 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Only
create extra subtypes for discriminants if the RM size of the base
type of the index type is lower than that of the index type.
2020-09-11 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/discr7.ads: New test.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1917 bytes --]
diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index 8045fa5ff97..2b7392c62c0 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -2480,8 +2480,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
tree gnu_base_orig_max = TYPE_MAX_VALUE (gnu_base_index_type);
tree gnu_min, gnu_max, gnu_high;
- /* We try to define subtypes for discriminants used as bounds
- that are more restrictive than those declared by using the
+ /* We try to create subtypes for discriminants used as bounds
+ that are more restrictive than those declared, by using the
bounds of the index type of the base array type. This will
make it possible to calculate the maximum size of the record
type more conservatively. This may have already been done by
@@ -2489,8 +2489,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
there will be a conversion that needs to be removed first. */
if (CONTAINS_PLACEHOLDER_P (gnu_orig_min)
&& TYPE_RM_SIZE (gnu_base_index_type)
- && !tree_int_cst_lt (TYPE_RM_SIZE (gnu_index_type),
- TYPE_RM_SIZE (gnu_base_index_type)))
+ && tree_int_cst_lt (TYPE_RM_SIZE (gnu_base_index_type),
+ TYPE_RM_SIZE (gnu_index_type)))
{
gnu_orig_min = remove_conversions (gnu_orig_min, false);
TREE_TYPE (gnu_orig_min)
@@ -2501,8 +2501,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition)
if (CONTAINS_PLACEHOLDER_P (gnu_orig_max)
&& TYPE_RM_SIZE (gnu_base_index_type)
- && !tree_int_cst_lt (TYPE_RM_SIZE (gnu_index_type),
- TYPE_RM_SIZE (gnu_base_index_type)))
+ && tree_int_cst_lt (TYPE_RM_SIZE (gnu_base_index_type),
+ TYPE_RM_SIZE (gnu_index_type)))
{
gnu_orig_max = remove_conversions (gnu_orig_max, false);
TREE_TYPE (gnu_orig_max)
[-- Attachment #3: discr7.ads --]
[-- Type: text/x-adasrc, Size: 287 bytes --]
-- { dg-do compile }
package Discr7 is
type Enum is (One, Two, Three);
for Enum use (One => 1, Two => 2, Three => 3);
type Arr is array (Integer range <>, Enum range <>) of Boolean;
type Rec (D : Integer) is record
A: Arr (1 .. D, Enum'Range);
end record;
end Discr7;
reply other threads:[~2020-09-11 9:23 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=15239409.lD0NLk8hKn@fomalhaut \
--to=botcazou@adacore.com \
--cc=gcc-patches@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).