From: Piotr Trojanek Date: Fri, 27 Sep 2024 08:47:29 +0000 (+0200) Subject: ada: Resolve intrinsic operators without homonyms X-Git-Tag: basepoints/gcc-16~4662 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ccd17b28e9bb9bd49676000c12e471a512c3a7cd;p=thirdparty%2Fgcc.git ada: Resolve intrinsic operators without homonyms Intrinsic operators are resolved by rewriting into a corresponding operator from the Standard package. Traversing homonyms just to find the corresponding operator was not particularly efficient; also, for the binary "-" it was finding the unary "-". There appears to be no difference in compiler behavior, but the new code should be more efficient and finding the correct operator seems to make more sense. gcc/ada/ChangeLog: * sem_res.adb (Resolve_Intrinsic_Operator) (Resolve_Intrinsic_Unary_Operator): Replace traversals of homonyms with a direct lookup. --- diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb index 0abdeee8fbee..2ea1ae4a3aee 100644 --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -9885,11 +9885,30 @@ package body Sem_Res is return; end if; - Op := Entity (N); - while Scope (Op) /= Standard_Standard loop - Op := Homonym (Op); - pragma Assert (Present (Op)); - end loop; + case N_Binary_Op'(Nkind (N)) is + when N_Op_Add => + Op := Standard_Op_Add; + when N_Op_Expon => + Op := Standard_Op_Expon; + when N_Op_Subtract => + Op := Standard_Op_Subtract; + when N_Op_Divide => + Op := Standard_Op_Divide; + when N_Op_Mod => + Op := Standard_Op_Mod; + when N_Op_Multiply => + Op := Standard_Op_Multiply; + when N_Op_Rem => + Op := Standard_Op_Rem; + + -- Non-arithmetic operators are handled elsewhere + + when N_Op_Boolean + | N_Op_Concat + | N_Op_Shift + => + raise Program_Error; + end case; Set_Entity (N, Op); Set_Is_Overloaded (N, False); @@ -9979,11 +9998,19 @@ package body Sem_Res is return; end if; - Op := Entity (N); - while Scope (Op) /= Standard_Standard loop - Op := Homonym (Op); - pragma Assert (Present (Op)); - end loop; + case N_Unary_Op'(Nkind (N)) is + when N_Op_Abs => + Op := Standard_Op_Abs; + when N_Op_Minus => + Op := Standard_Op_Minus; + when N_Op_Plus => + Op := Standard_Op_Plus; + + -- Non-arithmetic operators are handled elsewhere + + when N_Op_Not => + raise Program_Error; + end case; Set_Entity (N, Op);