public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Eric Botcazou <ebotcazou@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-7902] ada: Fix spurious error on 'Input of private type with Type_Invariant aspect Date: Wed, 27 Sep 2023 08:28:11 +0000 (GMT) [thread overview] Message-ID: <20230927082811.4202D3861932@sourceware.org> (raw) https://gcc.gnu.org/g:2d075e9aff49f9d09051edcefa8b37858d2150ef commit r13-7902-g2d075e9aff49f9d09051edcefa8b37858d2150ef Author: Eric Botcazou <ebotcazou@adacore.com> Date: Tue Jul 25 23:03:22 2023 +0200 ada: Fix spurious error on 'Input of private type with Type_Invariant aspect The problem is that it is necessary to break the privacy during the expansion of the Input attribute, which may introduce a view mismatch with the parameter of the routine checking the invariant of the type. gcc/ada/ * exp_util.adb (Make_Invariant_Call): Convert the expression to the type of the formal parameter if need be. Diff: --- gcc/ada/exp_util.adb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb index a110f447444..52c5753ab93 100644 --- a/gcc/ada/exp_util.adb +++ b/gcc/ada/exp_util.adb @@ -9869,11 +9869,16 @@ package body Exp_Util is ------------------------- function Make_Invariant_Call (Expr : Node_Id) return Node_Id is - Loc : constant Source_Ptr := Sloc (Expr); - Typ : constant Entity_Id := Base_Type (Etype (Expr)); + Loc : constant Source_Ptr := Sloc (Expr); + Typ : constant Entity_Id := Base_Type (Etype (Expr)); pragma Assert (Has_Invariants (Typ)); - Proc_Id : constant Entity_Id := Invariant_Procedure (Typ); + Proc_Id : constant Entity_Id := Invariant_Procedure (Typ); pragma Assert (Present (Proc_Id)); + Inv_Typ : constant Entity_Id + := Base_Type (Etype (First_Formal (Proc_Id))); + + Arg : Node_Id; + begin -- The invariant procedure has a null body if assertions are disabled or -- Assertion_Policy Ignore is in effect. In that case, generate a null @@ -9881,11 +9886,21 @@ package body Exp_Util is if Has_Null_Body (Proc_Id) then return Make_Null_Statement (Loc); + else + -- As done elsewhere, for example in Build_Initialization_Call, we + -- may need to bridge the gap between views of the type. + + if Inv_Typ /= Typ then + Arg := OK_Convert_To (Inv_Typ, Expr); + else + Arg := Relocate_Node (Expr); + end if; + return Make_Procedure_Call_Statement (Loc, Name => New_Occurrence_Of (Proc_Id, Loc), - Parameter_Associations => New_List (Relocate_Node (Expr))); + Parameter_Associations => New_List (Arg)); end if; end Make_Invariant_Call;
reply other threads:[~2023-09-27 8:28 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=20230927082811.4202D3861932@sourceware.org \ --to=ebotcazou@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: linkBe 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).