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 r13-232] [Ada] Fix hiding of user-defined operator that is not a homograph Date: Tue, 10 May 2022 08:21:26 +0000 (GMT) [thread overview] Message-ID: <20220510082126.D320338346AB@sourceware.org> (raw) https://gcc.gnu.org/g:7f8053225de072fed9c4822e589c853a6f5e47c4 commit r13-232-g7f8053225de072fed9c4822e589c853a6f5e47c4 Author: Eric Botcazou <ebotcazou@adacore.com> Date: Fri Jan 14 00:05:54 2022 +0100 [Ada] Fix hiding of user-defined operator that is not a homograph This adds a missing test for the presence of a homograph when applying the RM 8.4(10) clause about the visibility of operators, and removes resolution code made obsolete by the change. There is also a fixlet for a previously undetected ambiguity in the runtime. gcc/ada/ * sem_res.adb (Resolve_Eqyality_Op): Remove obsolete code. (Resolve_Op_Not): Likewise. * sem_type.adb (Disambiguate): Add missing test for RM 8.4(10). * libgnat/s-dwalin.adb (Enable_Cache): Fix ambiguity. (Symbolic_Address): Likewise. gcc/testsuite/ * gnat.dg/equal7.adb: Add expected error messages (code is now illegal). Diff: --- gcc/ada/libgnat/s-dwalin.adb | 5 ++- gcc/ada/sem_res.adb | 86 +--------------------------------------- gcc/ada/sem_type.adb | 9 +++-- gcc/testsuite/gnat.dg/equal7.adb | 10 ++++- 4 files changed, 19 insertions(+), 91 deletions(-) diff --git a/gcc/ada/libgnat/s-dwalin.adb b/gcc/ada/libgnat/s-dwalin.adb index 788be41c991..aff552cf57b 100644 --- a/gcc/ada/libgnat/s-dwalin.adb +++ b/gcc/ada/libgnat/s-dwalin.adb @@ -1544,7 +1544,7 @@ package body System.Dwarf_Lines is exit when Ar_Start = Null_Address and Ar_Len = 0; Len := uint32 (Ar_Len); - Start := uint32 (Ar_Start - C.Low); + Start := uint32 (Address'(Ar_Start - C.Low)); -- Search START in the array @@ -1764,7 +1764,8 @@ package body System.Dwarf_Lines is if C.Cache /= null then declare - Addr_Off : constant uint32 := uint32 (Addr - C.Low); + Addr_Off : constant uint32 := uint32 (Address'(Addr - C.Low)); + First, Last, Mid : Natural; begin First := C.Cache'First; diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 734e457975b..26da4ffc5c7 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -8962,55 +8962,6 @@ package body Sem_Res is Error_Msg_N ("?q?equality should be parenthesized here!", N); end if; - -- If the equality is overloaded and the operands have resolved - -- properly, set the proper equality operator on the node. The - -- current setting is the first one found during analysis, which - -- is not necessarily the one to which the node has resolved. - - if Is_Overloaded (N) then - declare - I : Interp_Index; - It : Interp; - - begin - Get_First_Interp (N, I, It); - - -- If the equality is user-defined, the type of the operands - -- matches that of the formals. For a predefined operator, - -- it is the scope that matters, given that the predefined - -- equality has Any_Type formals. In either case the result - -- type (most often Boolean) must match the context. The scope - -- is either that of the type, if there is a generated equality - -- (when there is an equality for the component type), or else - -- Standard otherwise. - - while Present (It.Typ) loop - if Etype (It.Nam) = Typ - and then - (Etype (First_Entity (It.Nam)) = Etype (L) - or else Scope (It.Nam) = Standard_Standard - or else Scope (It.Nam) = Scope (T)) - then - Set_Entity (N, It.Nam); - - Set_Is_Overloaded (N, False); - exit; - end if; - - Get_Next_Interp (I, It); - end loop; - - -- If expansion is active and this is an inherited operation, - -- replace it with its ancestor. This must not be done during - -- preanalysis because the type may not be frozen yet, as when - -- the context is a precondition or postcondition. - - if Present (Alias (Entity (N))) and then Expander_Active then - Set_Entity (N, Alias (Entity (N))); - end if; - end; - end if; - Check_Unset_Reference (L); Check_Unset_Reference (R); Generate_Operator_Reference (N, T); @@ -10594,42 +10545,9 @@ package body Sem_Res is end if; -- Complete resolution and evaluation of NOT - -- If argument is an equality and expected type is boolean, that - -- expected type has no effect on resolution, and there are - -- special rules for resolution of Eq, Neq in the presence of - -- overloaded operands, so we directly call its resolution routines. - - declare - Opnd : constant Node_Id := Right_Opnd (N); - Op_Id : Entity_Id; - - begin - if B_Typ = Standard_Boolean - and then Nkind (Opnd) in N_Op_Eq | N_Op_Ne - and then Is_Overloaded (Opnd) - then - Resolve_Equality_Op (Opnd, B_Typ); - Op_Id := Entity (Opnd); - - if Ekind (Op_Id) = E_Function - and then not Is_Intrinsic_Subprogram (Op_Id) - then - Rewrite_Operator_As_Call (Opnd, Op_Id); - end if; - - if not Inside_A_Generic or else Is_Entity_Name (Opnd) then - Freeze_Expression (Opnd); - end if; - - Expand (Opnd); - - else - Resolve (Opnd, B_Typ); - end if; - - Check_Unset_Reference (Opnd); - end; + Resolve (Right_Opnd (N), B_Typ); + Check_Unset_Reference (Right_Opnd (N)); Set_Etype (N, B_Typ); Generate_Operator_Reference (N, B_Typ); Eval_Op_Not (N); diff --git a/gcc/ada/sem_type.adb b/gcc/ada/sem_type.adb index 4cb0d8d9e9f..d5ee20b0c74 100644 --- a/gcc/ada/sem_type.adb +++ b/gcc/ada/sem_type.adb @@ -2215,13 +2215,14 @@ package body Sem_Type is return It2; end if; - -- An immediately visible operator hides a use-visible user- - -- defined operation. This disambiguation cannot take place - -- earlier because the visibility of the predefined operator - -- can only be established when operand types are known. + -- RM 8.4(10): an immediately visible operator hides a use-visible + -- user-defined operation that is a homograph. This disambiguation + -- cannot take place earlier because visibility of the predefined + -- operator can only be established when operand types are known. elsif Ekind (User_Subp) = E_Function and then Ekind (Predef_Subp) = E_Operator + and then Operator_Matches_Spec (Predef_Subp, User_Subp) and then Nkind (N) in N_Op and then not Is_Overloaded (Right_Opnd (N)) and then diff --git a/gcc/testsuite/gnat.dg/equal7.adb b/gcc/testsuite/gnat.dg/equal7.adb index 2b278424622..5e252a7f08c 100644 --- a/gcc/testsuite/gnat.dg/equal7.adb +++ b/gcc/testsuite/gnat.dg/equal7.adb @@ -1,4 +1,4 @@ --- { dg-do run } +-- { dg-do compile } with Equal7_Pkg; use Equal7_Pkg; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; @@ -13,3 +13,11 @@ begin null; end if; end; + +-- { dg-error "ambiguous expression \\(cannot resolve \"/=\"\\)" "" { target *-*-* } 9 } +-- { dg-error "possible interpretation at a-strunb.ads:\\d+" "" { target *-*-* } 9 } +-- { dg-error "possible interpretation in package Standard" "" { target *-*-* } 9 } + +-- { dg-error "ambiguous expression \\(cannot resolve \"=\"\\)" "" { target *-*-* } 12 } +-- { dg-error "possible interpretation at a-strunb.ads:\\d+" "" { target *-*-* } 12 } +-- { dg-error "possible interpretation in package Standard" "" { target *-*-* } 12 }
reply other threads:[~2022-05-10 8:21 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=20220510082126.D320338346AB@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: 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).