From patchwork Mon May 20 07:48:35 2024 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: 90450 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 B633B385840D for ; Mon, 20 May 2024 07:53:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id C3A663858CD1 for ; Mon, 20 May 2024 07:49:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C3A663858CD1 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 C3A663858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191361; cv=none; b=aB2W4CiHXf1ZvwevvDr/CmyqGGzcmrdUp/R+JTppUbrNdbF0UdAHpUSJWXALznw5d5wdbNgHu8Q06RMZQjnYnWtw/DrWaXd3J0N+vQW86CCNWEGLNZkz85C8QPWviwtLvnIzcqYVX4K0dErcDXGZDw6K/IIIazlzCM2i/uqOdCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716191361; c=relaxed/simple; bh=KgoTxNgScomYcoussegu1bPMrGhJykKfWJFm9GkR/Ik=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wYq23IZyqCnR8QDurQhC6LbSgoa2gQngZg1gYtW87VmdeuvPU59dvpy44vJFqpo/k9yIxS6xU8p3v03LoSS4VZcJGzgZk6JLjyaZCgs+sUJszloD93h9Ox0V1ZTrF0QKcPHL/moRIEmxXXKuHENXxddK7Auj4YGLdsnkIDy+2Ik= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-420180b5838so12885755e9.2 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=5WrXtKmqfKSf+EXpKpD57284fYM65Wysdee6iAIRrH4=; b=eCcpmx7qw//iAodNL+NH0lCyX3PsMmP6ckgYd5Q7chDAukWaYlajtYmEEIURd47M0M sVa6l+QAJAcsJ7dB7K7yiSQlJQwVgsZiaKK22zu3S9bPaHWgsoWLR4HBFSNleIbz6gsT jYahay+fSSPPKxIQnj4nnvuL/BLXBbkw11J2HKs5nt4BpqvSKVe9fkg6SybhTPxcMXuY LsXEoRVTeJ2Z3ndrAWoiojzXYpFSpWlqvt+eGxbQ8WCRms2inEcYPltDqUFDBgT4HUh3 viVfA1w2QftgYVg/6epp5qw6baHep0wVfVwAHdv0FcWzRg8A0jT5z5piePh0sWekMWo3 yweQ== 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=5WrXtKmqfKSf+EXpKpD57284fYM65Wysdee6iAIRrH4=; b=INNDMVVhqOtKGdisQHlOHbqNbzFPzJY7upOihAPpfr2EbmP4+THee34eULmM807WW9 xt+WcfMV2U6fS3ecF2hUB9pPpTfQokZy1Ja2JSoMxcNcPTU3xHW6biiPXgctY+czdxFh AoG4rC5K72ZAtUKomh+Ge7N26j+XW5oqiU03s1nk6xJP/CxHuyNmNPzx78jl+n5jib2o 6UAigiNEuQz45x/7GclfSKaR2b2Py2T6El2UXt31njbcvyAgRgSgMcpplWnw1HtntMO+ EISXaHwFReJypBZZa+p4EKpVYOmzZTtyi63BCupaDCiTrz2IgbVZyiePKMd/bhqsT4bb p7AQ== X-Gm-Message-State: AOJu0YzBg5UeobWxAkwHFeLpfNcxeh/5L8HKYhR8YT9UxQL767slhOHa Lrrrv4u701y14bi+Q1SKP/Bj2JdbZML8qPohYoUbePa0A/um5mBONNG/s0VBHGEQ7Oa6m82vO4E = X-Google-Smtp-Source: AGHT+IGYDWBuROMGv4rH222mxC/jWtXw5l1sr7qGEKSKSB8QEuQN4nCgjkxTD1Iaz6NLgbCdCWRaLA== X-Received: by 2002:a05:600c:474b:b0:41c:13f6:1eec with SMTP id 5b1f17b1804b1-41fea931ffemr264357855e9.3.1716191358646; Mon, 20 May 2024 00:49:18 -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:18 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED 09/30] ada: Fix static 'Img for enumeration type with Discard_Names Date: Mon, 20 May 2024 09:48:35 +0200 Message-ID: <20240520074858.222435-9-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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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 From: Piotr Trojanek Fix a short-circuit folding of 'Img for enumeration type, which wrongly ignored Discard_Names and exposed enumeration literals. gcc/ada/ * sem_attr.adb (Eval_Attribute): Handle enumeration type with Discard_Names. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_attr.adb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb index 96f216cc587..2b22cf13ad0 100644 --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -8221,13 +8221,26 @@ package body Sem_Attr is then declare Lit : constant Entity_Id := Expr_Value_E (P); + Typ : constant Entity_Id := Etype (Entity (P)); Str : String_Id; begin Start_String; - Get_Unqualified_Decoded_Name_String (Chars (Lit)); - Set_Casing (All_Upper_Case); - Store_String_Chars (Name_Buffer (1 .. Name_Len)); + + -- If Discard_Names is in effect for the type, then we emit the + -- numeric representation of the prefix literal 'Pos attribute, + -- prefixed with a single space. + + if Discard_Names (Typ) then + UI_Image (Enumeration_Pos (Lit), Decimal); + Store_String_Char (' '); + Store_String_Chars (UI_Image_Buffer (1 .. UI_Image_Length)); + else + Get_Unqualified_Decoded_Name_String (Chars (Lit)); + Set_Casing (All_Upper_Case); + Store_String_Chars (Name_Buffer (1 .. Name_Len)); + end if; + Str := End_String; Rewrite (N, Make_String_Literal (Loc, Strval => Str));