From: Steve Baird Date: Tue, 25 Oct 2022 23:59:29 +0000 (-0700) Subject: ada: Compile-time simplification of 'Image incorrectly ignores Put_Image X-Git-Tag: basepoints/gcc-14~3408 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=10f193eb043e30741d9631999bc869d71d43264c;p=thirdparty%2Fgcc.git ada: Compile-time simplification of 'Image incorrectly ignores Put_Image In the case of Some_Enumeration_Type'Image (), the compiler will replace this expression in its internal program representation with a corresponding string literal. This is incorrect if the Put_Image aspect has been specified (directly or via inheritance) for the enumeration type. gcc/ada/ * sem_attr.adb (Eval_Attribute): Don't simplify 'Image call if Put_Image has been specified. --- diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index de4e8aa681cd..5166b4be4e9d 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -9203,13 +9203,15 @@ package body Sem_Attr is -- Image is a scalar attribute, but is never static, because it is -- not a static function (having a non-scalar argument (RM 4.9(22)) -- However, we can constant-fold the image of an enumeration literal - -- if names are available. + -- if names are available and default Image implementation has not + -- been overridden. when Attribute_Image => if Is_Entity_Name (E1) and then Ekind (Entity (E1)) = E_Enumeration_Literal and then not Discard_Names (First_Subtype (Etype (E1))) and then not Global_Discard_Names + and then not Has_Aspect (Etype (E1), Aspect_Put_Image) then declare Lit : constant Entity_Id := Entity (E1);