public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <derodat@adacore.com>
To: gcc-patches@gcc.gnu.org
Cc: Ed Schonberg <schonberg@adacore.com>
Subject: [Ada] Use static discriminant value for discriminated task record
Date: Wed, 18 Sep 2019 08:42:00 -0000	[thread overview]
Message-ID: <20190918083945.GA145262@adacore.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 699 bytes --]

This patch allows the construction of a static subtype for the generated
constrained Secondary_Stack component of a task for which a stack size
is specified, when compiling for a restricted run-time that forbids
dynamic allocation. Needed for LLVM.

Tested on x86_64-pc-linux-gnu, committed on trunk

2019-09-18  Ed Schonberg  <schonberg@adacore.com>

gcc/ada/

	* sem_ch3.adb (Constrain_Component_Type): For a discriminated
	type, handle the case of a constraint given by a conversion of a
	discriminant of the enclosing type. Necessary when compiling a
	discriminated task for a restricted run-time, when the generated
	Secondary_Stack component may be set by means of an aspect on
	the task type.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1763 bytes --]

--- gcc/ada/sem_ch3.adb
+++ gcc/ada/sem_ch3.adb
@@ -13258,7 +13258,9 @@ package body Sem_Ch3 is
 
       function Build_Constrained_Discriminated_Type
         (Old_Type : Entity_Id) return Entity_Id;
-      --  Ditto for record components
+      --  Ditto for record components. Handle the case where the constraint
+      --  is a conversion of the discriminant value, introduced during
+      --  expansion.
 
       function Build_Constrained_Access_Type
         (Old_Type : Entity_Id) return Entity_Id;
@@ -13443,6 +13445,17 @@ package body Sem_Ch3 is
 
             if Is_Discriminant (Expr) then
                Need_To_Create_Itype := True;
+
+            --  After expansion of discriminated task types, the value
+            --  of the discriminant may be converted to a run-time type
+            --  for restricted run-times. Propagate the value of the
+            --  discriminant ss well, so that e.g. the secondary stack
+            --  component has a static constraint. Necessry for LLVM.
+
+            elsif Nkind (Expr) = N_Type_Conversion
+              and then Is_Discriminant (Expression (Expr))
+            then
+               Need_To_Create_Itype := True;
             end if;
 
             Next_Elmt (Old_Constraint);
@@ -13457,6 +13470,12 @@ package body Sem_Ch3 is
 
                if Is_Discriminant (Expr) then
                   Expr := Get_Discr_Value (Expr);
+
+               elsif Nkind (Expr) = N_Type_Conversion
+                 and then Is_Discriminant (Expression (Expr))
+               then
+                  Expr := New_Copy_Tree (Expr);
+                  Set_Expression (Expr, Get_Discr_Value (Expression (Expr)));
                end if;
 
                Append (New_Copy_Tree (Expr), To => Constr_List);


                 reply	other threads:[~2019-09-18  8:41 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=20190918083945.GA145262@adacore.com \
    --to=derodat@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=schonberg@adacore.com \
    /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).