From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 166F23857036 for ; Tue, 8 Nov 2022 08:44:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 166F23857036 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x332.google.com with SMTP id v7so8359252wmn.0 for ; Tue, 08 Nov 2022 00:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qxAZXYKQiyYiATLFVxa0yQNAmWgSsioXADXg2WCcNd8=; b=AMHCvYcNbgtxFWZhwD9lpvwCMyb83WdDw1PtSFHupbSVy/CDFZSLYdXtvV30Ap5kCF sNLYaGfp6PeJifkcEh3WNevH3YLpC+LcNHXxzZ1SV+rMktVejzzmJxF940KgYjClZ7dJ WI0/z+ZgPviWHib+TQ8as9Qfdey1x2mvrWj1fERioCiOEolrbNfLlyC0/ALjvucY34Yr YGuUFDHrg3P4sLtUkPdg9EdAy6cCKamdMK6FQ4ftCx6XNa+InevEaD70F5Z8B6asA623 oslXclQWbazi+svV/R0FzWLwsg4qoHfZdW1cY54LLvNae3APxjzV8fdLNfYYbWuvE061 hO9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qxAZXYKQiyYiATLFVxa0yQNAmWgSsioXADXg2WCcNd8=; b=EQv9d4OvdLyQ8bvCuB2Qr4CY6VRC5ukohIzl7ltPHTVt8XQ5UAQxczNL1Lm9OkahuU n3/9O/92xw+zCWHxcwWlC30QG4TgMgRrMGJ3lJkf8h4wS3Ev2GJbnquLdUgmwGgAKLOr LVw1tcmXG5CjUwU+Kcf29+ZKM87kJtmTK7ux+dLSPL/ia1Q9+lDtc907i2DSU6STCRs9 XB/+ZPlNywhE5QnctcDx4raRPnDKWrpIUd1/SNqp8g3mEkafTDpu/tqns/TGgMyEzKaw +cB9J6sBeSLa6cLX5/YKdRPmAPw1fXE1zBELGKF7xEXiES7HROTNUq8YQLizZ6zp37P7 C+BA== X-Gm-Message-State: ANoB5plPzqbArbs3nDpSGHf/SkDAN1i2nw4udb1q3M7A38dh1rVV0PwB r41d89iucsosuzT9CV77qZ49LroX5d6vUw== X-Google-Smtp-Source: AA0mqf6V7P9MA4t/dByUmMiaT3o9l0rrn556EjmRMi16sgtXu/fJNUfnvxXFayWCY16vsYc7ycVaLQ== X-Received: by 2002:a05:600c:4687:b0:3cf:a48f:f5af with SMTP id p7-20020a05600c468700b003cfa48ff5afmr9164991wmo.178.1667897038934; Tue, 08 Nov 2022 00:43:58 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id m3-20020a05600c3b0300b003cf47556f21sm14381923wms.2.2022.11.08.00.43.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 00:43:58 -0800 (PST) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [COMMITTED] ada: Compile-time simplification of 'Image incorrectly ignores Put_Image Date: Tue, 8 Nov 2022 09:43:55 +0100 Message-Id: <20221108084355.302230-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: From: Steve Baird 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. Tested on x86_64-pc-linux-gnu, committed on master. --- 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); -- 2.34.1