public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Pierre-Marie de Rodat <pmderodat@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-2114] [Ada] Unchecked_Convert_To: set Parent
Date: Wed,  7 Jul 2021 16:25:35 +0000 (GMT)	[thread overview]
Message-ID: <20210707162535.1C2BA395C068@sourceware.org> (raw)

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

commit r12-2114-gebef9784ef665511b407ed9081153a7eb52f816b
Author: Bob Duff <duff@adacore.com>
Date:   Wed May 19 07:52:32 2021 -0400

    [Ada] Unchecked_Convert_To: set Parent
    
    gcc/ada/
    
            * tbuild.adb (Unchecked_Convert_To): Set the Parent of the new
            node to the Parent of the old node.
            * tbuild.ads (Unchecked_Convert_To): Document differences
            between Convert_To and Unchecked_Convert_To. The previous
            documentation claimed they are identical except for the
            uncheckedness of the conversion.

Diff:
---
 gcc/ada/tbuild.adb | 13 +++++++++----
 gcc/ada/tbuild.ads |  5 ++++-
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/gcc/ada/tbuild.adb b/gcc/ada/tbuild.adb
index e7186444365..4d9c1c410fd 100644
--- a/gcc/ada/tbuild.adb
+++ b/gcc/ada/tbuild.adb
@@ -919,10 +919,15 @@ package body Tbuild is
       --  All other cases
 
       else
-         Result :=
-           Make_Unchecked_Type_Conversion (Loc,
-             Subtype_Mark => New_Occurrence_Of (Typ, Loc),
-             Expression   => Relocate_Node (Expr));
+         declare
+            Expr_Parent : constant Node_Id := Parent (Expr);
+         begin
+            Result :=
+              Make_Unchecked_Type_Conversion (Loc,
+                Subtype_Mark => New_Occurrence_Of (Typ, Loc),
+                Expression   => Relocate_Node (Expr));
+            Set_Parent (Result, Expr_Parent);
+         end;
       end if;
 
       Set_Etype (Result, Typ);
diff --git a/gcc/ada/tbuild.ads b/gcc/ada/tbuild.ads
index f2f9809eb73..eb17865ad4f 100644
--- a/gcc/ada/tbuild.ads
+++ b/gcc/ada/tbuild.ads
@@ -340,7 +340,10 @@ package Tbuild is
      (Typ  : Entity_Id;
       Expr : Node_Id) return Node_Id;
    --  Like Convert_To, but if a conversion is actually needed, constructs an
-   --  N_Unchecked_Type_Conversion node to do the required conversion.
+   --  N_Unchecked_Type_Conversion node to do the required conversion. Unlike
+   --  Convert_To, a new node is not required if Expr is already of the correct
+   --  BASE type, and if a new node is created, the Parent of Expr is copied to
+   --  it.
 
    -------------------------------------
    -- Subprograms for Use by Gnat1drv --


                 reply	other threads:[~2021-07-07 16:25 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=20210707162535.1C2BA395C068@sourceware.org \
    --to=pmderodat@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).