public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Marc Poulhiès" <poulhies@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Eric Botcazou <ebotcazou@adacore.com>
Subject: [COMMITTED] ada: Fix assertion failure on very peculiar enumeration type
Date: Tue,  5 Sep 2023 13:08:22 +0200	[thread overview]
Message-ID: <20230905110822.563115-1-poulhies@adacore.com> (raw)

From: Eric Botcazou <ebotcazou@adacore.com>

The compiler currently does not support the combination of a representation
clause on an enumeration type with a size clause whose value is greater than
the size of the largest machine scalar supported by the target.

Given that such a type would have little practical value, this change causes
the compiler to give a proper error message instead of aborting.

gcc/ada/

	* freeze.adb (Freeze_Enumeration_Type): Give an error on a type with
	both representation clause and too large size.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/freeze.adb | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 38aeb2456ff..0fc33a420c2 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -8023,6 +8023,20 @@ package body Freeze is
 
          Adjust_Esize_For_Alignment (Typ);
       end if;
+
+      --  Reject a very large size on a type with a non-standard representation
+      --  because Expand_Freeze_Enumeration_Type cannot deal with it.
+
+      if Has_Non_Standard_Rep (Typ)
+        and then Known_Esize (Typ)
+        and then Esize (Typ) > System_Max_Integer_Size
+      then
+         Error_Msg_N
+           ("enumeration type with representation clause too large", Typ);
+         Error_Msg_Uint_1 := UI_From_Int (System_Max_Integer_Size);
+         Error_Msg_N
+           ("\the size of such a type cannot exceed ^ bits", Typ);
+      end if;
    end Freeze_Enumeration_Type;
 
    -----------------------
-- 
2.40.0


                 reply	other threads:[~2023-09-05 11:08 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=20230905110822.563115-1-poulhies@adacore.com \
    --to=poulhies@adacore.com \
    --cc=ebotcazou@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).