diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2022-01-14 00:05:54 +0100 |
---|---|---|
committer | Pierre-Marie de Rodat <derodat@adacore.com> | 2022-05-10 08:19:23 +0000 |
commit | 7f8053225de072fed9c4822e589c853a6f5e47c4 (patch) | |
tree | 3cca2df6a508114bb16be38e971920fb4d707482 /gcc | |
parent | 6798cad793d9581936f2de76c85a22a5449d7358 (diff) | |
download | gcc-7f8053225de072fed9c4822e589c853a6f5e47c4.zip gcc-7f8053225de072fed9c4822e589c853a6f5e47c4.tar.gz gcc-7f8053225de072fed9c4822e589c853a6f5e47c4.tar.bz2 |
[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).
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/libgnat/s-dwalin.adb | 5 | ||||
-rw-r--r-- | gcc/ada/sem_res.adb | 86 | ||||
-rw-r--r-- | gcc/ada/sem_type.adb | 9 | ||||
-rw-r--r-- | 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 788be41..aff552c 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 734e457..26da4ff 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 4cb0d8d..d5ee20b 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 2b27842..5e252a7 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 } |