public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Marc Poulhi?s <dkm@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-3789] ada: Improve handling of declare expressions in deferred-freezing contexts
Date: Tue,  8 Nov 2022 08:41:31 +0000 (GMT)	[thread overview]
Message-ID: <20221108084131.4712E3858437@sourceware.org> (raw)

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

commit r13-3789-gf2fa41b442ae6b6ab1fbde82d31abcd986b9f1f3
Author: Steve Baird <baird@adacore.com>
Date:   Wed Oct 19 12:42:55 2022 -0700

    ada: Improve handling of declare expressions in deferred-freezing contexts
    
    In some cases where a declare expression occurs in a deferred-freezing
    context (e.g., within the default value for a discriminant or for a formal
    parameter, or within the expression of an expression function), the compiler
    generates a bugbox.
    
    gcc/ada/
    
            * sem_ch3.adb
            (Analyze_Object_Declaration): Do not perform expansion actions if
            In_Spec_Expression is true.

Diff:
---
 gcc/ada/sem_ch3.adb | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb
index 8f4e9f80eb8..95ffbe00ba4 100644
--- a/gcc/ada/sem_ch3.adb
+++ b/gcc/ada/sem_ch3.adb
@@ -4721,6 +4721,26 @@ package body Sem_Ch3 is
                   Expand_Sliding_Conversion (E, T);
                end if;
 
+               if In_Spec_Expression and then In_Declare_Expr > 0 then
+                  --  It is too early to be doing expansion-ish things,
+                  --  so exit early. But we have to set Ekind (Id) now so
+                  --  that subsequent uses of this entity are not rejected
+                  --  via the same mechanism that (correctly) rejects
+                  --  "X : Integer := X;".
+
+                  if Constant_Present (N) then
+                     Mutate_Ekind         (Id, E_Constant);
+                     Set_Is_True_Constant (Id);
+                  else
+                     Mutate_Ekind (Id, E_Variable);
+                     if Present (E) then
+                        Set_Has_Initial_Value (Id);
+                     end if;
+                  end if;
+
+                  goto Leave;
+               end if;
+
                Expand_Subtype_From_Expr
                  (N             => N,
                   Unc_Type      => T,

                 reply	other threads:[~2022-11-08  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=20221108084131.4712E3858437@sourceware.org \
    --to=dkm@gcc.gnu.org \
    --cc=gcc-cvs@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).