From a3c3de386bfce7910745386f727fe6b5f83d2906 Mon Sep 17 00:00:00 2001 From: Richard Kenner Date: Wed, 8 Dec 2021 17:11:26 -0500 Subject: [PATCH] [Ada] Use non-internal representation for access subprograms if UC to Address gcc/ada/ * libgnat/g-spipat.ads (Boolean_Func, Natural_Func, VString_Func): Mark as Favor_Top_Level. * sem_ch13.adb (Validate_Unchecked_Conversion): Avoid using internal representation if Unchecked_Conversion between an access to subprogram and System.Address within the same unit. --- gcc/ada/libgnat/g-spipat.ads | 6 +++--- gcc/ada/sem_ch13.adb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gcc/ada/libgnat/g-spipat.ads b/gcc/ada/libgnat/g-spipat.ads index 13d1e939086..7b103c0d858 100644 --- a/gcc/ada/libgnat/g-spipat.ads +++ b/gcc/ada/libgnat/g-spipat.ads @@ -654,19 +654,19 @@ package GNAT.Spitbol.Patterns is -- operations for constructing patterns that can be used in the pattern -- matching operations provided. - type Boolean_Func is access function return Boolean; + type Boolean_Func is access function return Boolean with Favor_Top_Level; -- General Boolean function type. When this type is used as a formal -- parameter type in this package, it indicates a deferred predicate -- pattern. The function will be called when the pattern element is -- matched and failure signalled if False is returned. - type Natural_Func is access function return Natural; + type Natural_Func is access function return Natural with Favor_Top_Level; -- General Natural function type. When this type is used as a formal -- parameter type in this package, it indicates a deferred pattern. -- The function will be called when the pattern element is matched -- to obtain the currently referenced Natural value. - type VString_Func is access function return VString; + type VString_Func is access function return VString with Favor_Top_Level; -- General VString function type. When this type is used as a formal -- parameter type in this package, it indicates a deferred pattern. -- The function will be called when the pattern element is matched diff --git a/gcc/ada/sem_ch13.adb b/gcc/ada/sem_ch13.adb index 81735328cab..f462951b301 100644 --- a/gcc/ada/sem_ch13.adb +++ b/gcc/ada/sem_ch13.adb @@ -17546,6 +17546,22 @@ package body Sem_Ch13 is Set_No_Strict_Aliasing (Implementation_Base_Type (Target)); end if; + -- If the unchecked conversion is between Address and an access + -- subprogram type, show that we shouldn't use an internal + -- representation for the access subprogram type. + + if Is_Access_Subprogram_Type (Target) + and then Is_Descendant_Of_Address (Source) + and then In_Same_Source_Unit (Target, N) + then + Set_Can_Use_Internal_Rep (Target, False); + elsif Is_Access_Subprogram_Type (Source) + and then Is_Descendant_Of_Address (Target) + and then In_Same_Source_Unit (Source, N) + then + Set_Can_Use_Internal_Rep (Source, False); + end if; + -- Generate N_Validate_Unchecked_Conversion node for back end in case -- the back end needs to perform special validation checks. -- 2.34.1