From patchwork Tue Nov 8 08:43:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 16956 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2576937wru; Tue, 8 Nov 2022 01:01:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM62BS/lO9P426JZMMzmAuuE42ZGMZmGGbVM7OhXRR9/3cNFga9AGqlxer48bQUtU7n4bkbU X-Received: by 2002:a05:6402:d5:b0:464:7023:634 with SMTP id i21-20020a05640200d500b0046470230634mr21838803edu.165.1667898072988; Tue, 08 Nov 2022 01:01:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667898072; cv=none; d=google.com; s=arc-20160816; b=fx9YXoYJNPGXOL71KcFdHlig0iwN9xNXR4w9jjR9r8dLtVozQ/0xW6KCRbHt9FQ0Yo dsEXFGK8nGZjJCta2M4cUrH5MBuR89VEMn9R0qo6eHljv8pxsGHfzy4K1Yf6F+dOROC1 fTVkf/QJ7qpAJAPDQDe3qd464ifMX326GUPMrtNciAB9Au/DHOxYK66+MWh79jHtDfGE kt1QHEjeSN0KNDQu8YokppQel71mifaTvrBvo+qUWVDeG8nXW5GQ6WnpaPezipMmH0QK /OAKSZMqblR6Ogg3TpO5ffcCu/aKES8kYULHGAwXDoQU3WFppg6jrtApr69abvbD7VOn D8TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=qxAZXYKQiyYiATLFVxa0yQNAmWgSsioXADXg2WCcNd8=; b=KDKtZZaT53I0GwNDg+SPvpWdOUDfB4tgoYin/2EhZO++hqMPdiTKkzAxrHauDZwCLr haNyx+UvZ/iOwkqGbGrncEPXV5VnMTXbTAVYla0djfHb9YC+OQCze1dkPrLr8gO+uW19 9r9Xh10kth4mukB2l2O0iAZSpxeoiOvMHylLQW2AJFCbbn6nVHZn7hzu4q/lNujmHGnM TqmINqeD11u0/QbzrKCwy6zr4+OadnEjbew6iIEi4DBAjthUgpX5L/OgNA28ZgFW5Cey Q2t0awSEeDeIyrMsqijEyC6bq9C0eKkcxi/YiBoxSeqihmkKlChmgsc/LCenn20WDE+y RulA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FzfPreMi; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l7-20020a170906644700b007a9fc5516f6si7581113ejn.307.2022.11.08.01.01.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 01:01:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FzfPreMi; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9355A388302C for ; Tue, 8 Nov 2022 08:54:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9355A388302C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667897690; bh=qxAZXYKQiyYiATLFVxa0yQNAmWgSsioXADXg2WCcNd8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FzfPreMivNK7db9BMqBSDXNYwXmVie+4r6PBXAO6a3hCLQg1tOpCpZ+32s0MCu14y iZ3NPqUD/NNFhM7fOuHa+LdLf9Y1oGe8ZNsaZjwDEytBE//lP8k7e2H1S6J8VLArmp wReL8gNPPWd685gw6bSqKdzEn+0O1Db7NIn0+/9Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 Received: by mail-wm1-x332.google.com with SMTP id v7so8359252wmn.0 for ; Tue, 08 Nov 2022 00:44:00 -0800 (PST) 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-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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748917889382538357?= X-GMAIL-MSGID: =?utf-8?q?1748917889382538357?= 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);