From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 1BB153857C6F; Tue, 8 Nov 2022 08:42:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1BB153857C6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667896943; bh=fSkP5nPr9S6x0Z25FzhSJMF15gimU2b+XJD8jPfASxU=; h=From:To:Subject:Date:From; b=DL7U64SGmIaen7dpBlkHQPTGps0QCODxYey3LEzsVKg5GdKBHzi0fdRe14vUqiSXN TZMQpqcnbJIrcLZGga2muHum51cmsfEk+iDPngJ2Hzww72/V2D18FnIcPdcICznFHF DF36Qwr66bnNcPz+NzuPRaybg2hKMWtpSAg6EaKA= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3799] ada: Compile-time simplification of 'Image incorrectly ignores Put_Image X-Act-Checkin: gcc X-Git-Author: Steve Baird X-Git-Refname: refs/heads/master X-Git-Oldrev: 11f892571c7ab4964f16c0d432e6f5a9b4a091f1 X-Git-Newrev: 10f193eb043e30741d9631999bc869d71d43264c Message-Id: <20221108084223.1BB153857C6F@sourceware.org> Date: Tue, 8 Nov 2022 08:42:23 +0000 (GMT) List-Id: https://gcc.gnu.org/g:10f193eb043e30741d9631999bc869d71d43264c commit r13-3799-g10f193eb043e30741d9631999bc869d71d43264c Author: Steve Baird Date: Tue Oct 25 16:59:29 2022 -0700 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: --- gcc/ada/sem_attr.adb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index de4e8aa681c..5166b4be4e9 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);