From patchwork Tue Sep 14 09:36:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 44987 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AD1793857C7B for ; Tue, 14 Sep 2021 09:38:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 645033857C6C for ; Tue, 14 Sep 2021 09:36:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 645033857C6C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x334.google.com with SMTP id v20-20020a1cf714000000b002e71f4d2026so1561703wmh.1 for ; Tue, 14 Sep 2021 02:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Pw5hJjs3GIhheZ9g7fnr2uljqw0sshW+VcInITZUNJU=; b=GEwtRi3STsz/p0v3gkp9RP5r5/zJ+m7SoQK1cycVWr7uaDc+Oa3Y24MZzvE5UU4Nnd DQi2dTF0RjrmpILXaqUFkbCQUNfpT4ebzXYWtgY3oDSW2yGz+CJju4d6EuvCDO3x7pnk h4gaU1/JQ8sq2KMqCvPt4PZnzJQYnUa/Owlvwyho3xUksGaEiQN4OSxkaMQLAo2mmrAJ ddzOFnfpPMzuvXTr9pZ7GMHheCEDKkk+1SRtJYCICBGF2len+TQRFa4872tA7Obi9tic 70RT9vSsSXGmaQw3m+1VUIjZyfCceLTkWwFrGi6LKn5p1wDNewDCLapQkhDXG2Muza4S mTGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=Pw5hJjs3GIhheZ9g7fnr2uljqw0sshW+VcInITZUNJU=; b=c3NYaeCXLLTpY4VeENpsdsDmfWPYIxMEIfj0QHMaPPTDGvT/AEpoxkCx2YFW8m0ZWN JVkmLKbRwhnfioxUYvkVrK6yNC7G1RPHQSJFrcFSBmCLSx6PC17OJZHJha4oHg5n0auJ OLF4ei7rHK4TjzNTU7Kozl4O234PfifY5UK1mvHMW3H8V0nQ514skI9sdorleMfR/t3y xsrpQ0KACR/G8zoPEPEKqK6kGGwBOzPSDsGCWSIDvatm0IfrWRj5Qn/xcKQOlIetttMg SJAe7FNVx+qDF3u6klZhlwjxh5Ej8B5M13IBedzPdbAagDuyZlIzsvQ1jE8avysUF6Ei BVgA== X-Gm-Message-State: AOAM532SwuRKs3M4EGbjor4OIHE3R2vwdPb9U6DMLb9KAw+A+sLUskzA fR1eaq8FxeOUckr4IJtx2SsrEjlGgbadPeHi X-Google-Smtp-Source: ABdhPJyw1Ye5iJeysq3BNXhJTKbX32TEbx6Zu1pWQY2esEwSFXhN34eKp/zU1E0s4cLk9U4BF18fEg== X-Received: by 2002:a05:600c:3641:: with SMTP id y1mr1069499wmq.43.1631612186308; Tue, 14 Sep 2021 02:36:26 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id u13sm9783615wrt.41.2021.09.14.02.36.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Sep 2021 02:36:25 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix PR ada/101970 Date: Tue, 14 Sep 2021 11:36:14 +0200 Message-ID: <22354165.6Emhk5qWAg@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SCC_10_SHORT_WORD_LINES, SCC_20_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This is a regression present on the mainline and 11 branch in the form of an ICE for an enumeration type with a full signed representation for its size. Tested on x86-64/Linux, applied on the mainline and 11 branch. 2021-09-14 Eric Botcazou PR ada/101970 * exp_attr.adb (Expand_N_Attribute_Reference) : Use an unchecked conversion instead of a regular conversion in the enumeration case and remove Conversion_OK flag in the integer case. : Remove superfluous test. 2021-09-14 Eric Botcazou * gnat.dg/enum_rep2.adb: New test. diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb index f074521e5f7..fc6b0ef8097 100644 --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -3252,14 +3252,15 @@ package body Exp_Attr is -- If not constant-folded, Enum_Type'Enum_Rep (X) or X'Enum_Rep -- expands to - -- target-type (X) + -- target-type!(X) - -- This is simply a direct conversion from the enumeration type to - -- the target integer type, which is treated by the back end as a - -- normal integer conversion, treating the enumeration type as an - -- integer, which is exactly what we want. We set Conversion_OK to - -- make sure that the analyzer does not complain about what otherwise - -- might be an illegal conversion. + -- This is an unchecked conversion from the enumeration type to the + -- target integer type, which is treated by the back end as a normal + -- integer conversion, treating the enumeration type as an integer, + -- which is exactly what we want. Unlike for the Pos attribute, we + -- cannot use a regular conversion since the associated check would + -- involve comparing the converted bounds, i.e. would involve the use + -- of 'Pos instead 'Enum_Rep for these bounds. -- However the target type is universal integer in most cases, which -- is a very large type, so in the case of an enumeration type, we @@ -3267,11 +3268,13 @@ package body Exp_Attr is -- the size information. if Is_Enumeration_Type (Ptyp) then - Rewrite (N, OK_Convert_To (Get_Integer_Type (Ptyp), Expr)); + Rewrite (N, Unchecked_Convert_To (Get_Integer_Type (Ptyp), Expr)); Convert_To_And_Rewrite (Typ, N); + -- Deal with integer types (replace by conversion) + else - Rewrite (N, OK_Convert_To (Typ, Expr)); + Rewrite (N, Convert_To (Typ, Expr)); end if; Analyze_And_Resolve (N, Typ); @@ -5420,7 +5423,7 @@ package body Exp_Attr is -- Deal with integer types (replace by conversion) - elsif Is_Integer_Type (Etyp) then + else Rewrite (N, Convert_To (Typ, Expr)); end if;