From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 2909C3858403 for ; Mon, 20 May 2024 07:49:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2909C3858403 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2909C3858403 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191361; cv=none; b=sdJNrnSrhTNsQnnuHM4FTEZWPRVWq727sTovo1is0XT1CdQjYG2KmIi2wT8SXQCjZ37yv8wdPR+Cmx/RRhprvjLWdvVIRBkND+j2U/Fm7+6soB9POm7nGAeJRp9C6bIJp9YvDWhjD2WLo+pd++GwMVmAypJwNUp4W0IuHW/tYVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191361; c=relaxed/simple; bh=zt4kz9B0pSUjV9bCCrs5RrA6j4J2Bw599PNsbFFLazE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nZTPILNxDJuF1FcvKb41NHyM7YWSqMlT65q5zy9uhEbcvf/4V83OP2mH0MNQTVS8rS+uapFZF0ZfgX5zx+ePFyUft0KFOcAuCOvaZjErc1vTuTRBBlQLY13yKedZwZDhApHhdtxiOjQRt9zx6qcrh9cCaMjSRPNyiivwIbH7OfU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4202cea98daso16764455e9.0 for ; Mon, 20 May 2024 00:49:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716191358; x=1716796158; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xljmk/iOXloSRem+o6FzWxzUQCwGYHUriL6rCFlGHGA=; b=X/W1RmLT2SD8+4SsrZhmUX7fHmq4it5WNXXMhTUcDiHoo/lMxKGzAGrFaAkQ1WOGx6 9rq7vNGgKhdJbL0LDQUoiV70YTOM9y5X5H5b05mkhXFkxklmu5nZh6HR54ODkHBE2vve X7k5CHmUtziSEDuTvbAaPzeCXZo58gKiPxsOPQtToBrtR6CMyTRUcAgT7kU9L763U+zc QEuZp/G91e2zE+Za0/7DoCH4ZSrOykPpGIfSSIGYFLacgVynpD4jKnZN4m8xO3LXBl3s TlAj7D3zARN9xuM4UvmPH+d/Ticd5ZR32kpngpiY5ZRvS3XG3q4gTUPnASCE3fryYp7f AUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716191358; x=1716796158; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xljmk/iOXloSRem+o6FzWxzUQCwGYHUriL6rCFlGHGA=; b=X8AOykDsYsgVo7mMVbRzFUUkCs9RrdJk1uxm02cijf3cgMjhd1D6C7y6iS2tDmijQC No6zdcOSueBUn9MYFRJ9ioVggcTIzzHU+RFHxZK3yN+QO6pXD25pqpm05f4Jv9fjClJU hmVLpkHV6ValGk98YVHbdCcooYcSy+HKbuQwCrwNCpehV3rO2/QIxQyePQ4V2U0MjWjn QZko2O8mCDXsT8SfJRKUwCyDNR2VDzqpClBRzsXRky22RUpMKgsKnpRj0P2vV3ZlOnI1 YkjARZPAvBWmm7Sxnlx8AX2wSK9tBtUlqFGiZWpo1++mk8ZZLhWY0T72gz6Eyv1x/qqS yGuA== X-Gm-Message-State: AOJu0YyRzk3rar4LQGLMlIuBQiuzPH5k3JgFupCFOvnXpPYllYXiqZ2c x9EFBK2yPHS3syDcBJJ46DkMesIFujfo9CMeK5szcYdi48VqKwyNJWWU79gE0j8yiQq9JoeApE8 = X-Google-Smtp-Source: AGHT+IGFkHTFcu2pk8nUAmnruMDA4z+GklQhdbtlObPuhUGHkn8W97GpOPxMdbJjLMTSzFXFbEpPzg== X-Received: by 2002:a05:600c:45cc:b0:41f:f592:2fa3 with SMTP id 5b1f17b1804b1-41ff5922fb3mr185499735e9.11.1716191357866; Mon, 20 May 2024 00:49:17 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41f88111033sm446892175e9.34.2024.05.20.00.49.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 00:49:17 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED 08/30] ada: Fix for attribute Width on enumeration types with Discard_Name Date: Mon, 20 May 2024 09:48:34 +0200 Message-ID: <20240520074858.222435-8-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240520074858.222435-1-poulhies@adacore.com> References: <20240520074858.222435-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.9 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: Piotr Trojanek Fix computation of attribute 'Width for enumeration types with Discard_Name aspect enabled. gcc/ada/ * exp_imgv.adb (Expand_Width_Attribute): Fix for 'Width that is computed at run time. * sem_attr.adb (Eval_Attribute): Fix for 'Width that is computed at compilation time. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/exp_imgv.adb | 25 +++++++++++++++---------- gcc/ada/sem_attr.adb | 7 ++++--- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/gcc/ada/exp_imgv.adb b/gcc/ada/exp_imgv.adb index 6dc59f2c6f3..e5d84cc52e3 100644 --- a/gcc/ada/exp_imgv.adb +++ b/gcc/ada/exp_imgv.adb @@ -2294,7 +2294,7 @@ package body Exp_Imgv is -- in the range of the subtype + 1 for the space at the start. We -- build: - -- Tnn : constant Integer := Rtyp'Pos (Ptyp'Last) + -- Tnn : constant Integer := Rtyp'Pos (Ptyp'Last); -- and replace the expression by @@ -2320,9 +2320,15 @@ package body Exp_Imgv is declare Tnn : constant Entity_Id := Make_Temporary (Loc, 'T'); Cexpr : Node_Id; - P : Int; - M : Int; - K : Int; + + P : constant Nat := + UI_To_Int (Enumeration_Pos (Entity (Type_High_Bound (Rtyp)))); + -- The largest value that might need to be represented + + K : Pos; + M : Pos; + -- K is the number of chars that will fit the image of 0..M-1; + -- M is the smallest number that won't fit in K chars. begin Insert_Action (N, @@ -2342,14 +2348,13 @@ package body Exp_Imgv is Attribute_Name => Name_Last)))))); -- OK, now we need to build the if expression. First get the - -- value of M, the largest possible value needed. + -- values of K and M for the largest possible value P. - P := UI_To_Int - (Enumeration_Pos (Entity (Type_High_Bound (Rtyp)))); + K := 2; + M := 10; + -- With 2 characters we can represent values in 0..9 - K := 1; - M := 1; - while M < P loop + while P >= M loop M := M * 10; K := K + 1; end loop; diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index a921909685a..96f216cc587 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -10906,9 +10906,10 @@ package body Sem_Attr is -- that accommodates the Pos of the largest value, which -- is the high bound of the range + one for the space. - W := 1; - T := Hi; - while T /= 0 loop + W := 1; -- one character for the leading space + W := W + 1; -- one character for the 0 .. 9 digit + T := Hi; -- one character for every decimal digit + while T >= 10 loop T := T / 10; W := W + 1; end loop; -- 2.43.2