From patchwork Tue Jun 2 08:45:34 2026 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: 136281 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C34724BA2E32 for ; Tue, 2 Jun 2026 09:29:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C34724BA2E32 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=eVHS5e7s X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id 9D0F74BA23C5 for ; Tue, 2 Jun 2026 08:46:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D0F74BA23C5 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 9D0F74BA23C5 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::331 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780389995; cv=none; b=EwmwqN2gwHJn/rOHsdK/iWfMYYfk0hx11AX78RuE63KUL1AwSYx2rJvNCHhktEZHTE9Yu9ZsVhW0/5sDcEYL6GsiZp95yiZTKhbUNn/F/9DAbQvqGGo4NVO9sR4OMMJAs76LwL/J+aTyS7cH62R/ThLnBlkcUCiTvx4a3yJdBpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780389995; c=relaxed/simple; bh=A9nwrxlL98YN71oVYlT8nU2W/HEBkNvqSLuGAyk8BKE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rR7YIltHJFhwcWhcoY7RvlHry/4B01YM38tNnjz8eq+EoRjmuattWl3xsJqUFNZQ5KHTlOfhjMeDXUoSJwbbJCK4yQ4G74UI43lx0W03aSA4Hg4nLr65oZ+Gi5yrfUiNSn4sl2l1/M5cntmlH/05wdemuJlSfM6NtpocoOTH6/Y= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=eVHS5e7s DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9D0F74BA23C5 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-490686877a1so66171005e9.0 for ; Tue, 02 Jun 2026 01:46:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1780389994; x=1780994794; 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=oHiDd4PttWdnJRvKnnmhkUCeD03jZGX5qUY1ngIHm/A=; b=eVHS5e7sZatqfSHhW43LAXfjb/1vfJkKRyUFCJgPmVCZyqM3rJDNOy/u0+MIA9Sh5k UkseYHr4v9sh0N7UEFBRzQIDkeBKwjN5j+tVdaOMoXLu+zxKTY6jtNBZ5JenBw6b674X 0rzUigi88KoSPqehDZvTRUvJ1qXAytjF2+X5n+u1sUkAQPiYq4Gh7GEv4VEp9Wdd1WzN kzZRHTlzelWTITHYmomhwdMQwpZ61eb8hQ8hsmlsO5xku7uQ2SgX71yQrBwhRUfuq1F1 x2CGcrxl1amy2/J4ox4IMVZSxzAg2iC4w6+MsgfHvrs0wc3eTIoTlLz4p5A9oQp8sQoH 7wbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780389994; x=1780994794; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=oHiDd4PttWdnJRvKnnmhkUCeD03jZGX5qUY1ngIHm/A=; b=mpYNVb8iUP71x7JXriRFYZ0huqB/FEaa7/uTcEXB6hAJ5H6UpMiv6ZxZeS+arNMmOh rBFYNZ9BtxsNiqZoBwmOE8GCHuPX1rTyloHNDvlkL1/KB4ke5ejIugPkz10NbHAXqnVf AvHTtrS2qMZEp86QWCv5gch4+UsD6CWvQJ9aJLymZrLyZWFWqVNutUmXSJPuMeby68tI ljOm+/HgrhovDH6E4eeDWgO4N4ZIyqVotcWAMiJPdDX/s8LX+/AM09eS3ChsJpjlZm6L dKDVDOl/4OSRPfhTtd2aJWQ1g8e9fU+45kkuJJrxuNcNysyMtVuOoYL3awj9MZS+7yEA gn6g== X-Gm-Message-State: AOJu0Yxs4VbqN6aDVW+P0DU32fkkoXJRgwd6JGC5exanVXmNSYANIgt9 IoDqLJ7eCOvrxcny/DSo9WbajYpg0Lk+7FxL/sICq4znLsB6sUjduSUo11bBAD6lESJMbkYhpwL K73Y= X-Gm-Gg: Acq92OGnYuGhZlbd1F8lEWr9etkhVCsM9SDlKzTpPXLnklzJwN0UdJ08JBn+BL1M8o7 sS6v1Iqrbq9G9jWaMfokHzjsrDDuChMlm0YrZFw+n0/IcxzfaJvQlvC8x96MWRPebioDgCTRTEA nwVQ1QTuHE3FFY5F8aURS8LjPQYfvQP+bKHfpzUd94ZmB69JpQ3dedM/7mNPI+jTNWba4aSNJ8F 7EC+hXI/Cf2Z4MwmoN/BlxBHjGVYk43m8xdXKBme1bJ148aJqoFYEE6BZITaGvlpEjg/Pas9tlz jdOPqbVEjaA1Y4Eqvjca6gzPBNnf6ThbSDMagjkyoy3ujbngFJU+dmdeiBzTLFWD2cgg4KsY/6+ /+ydNOzOcM9wYkJEy+N9qGynbxYhRxAlAPpB7ZD2k891TKa3HquhGxQ/h/Zk6DosMKDPQndf5Pn w1q0ggIa7DLlS+I9JTE21vxHGrsZ1Hswm+5ws6UVTkC2w4avA7UplrmG+hV5tfJElDf1mD3VIS1 8sR7UzD7N5m0uJblsIeOjEJCQuthHc= X-Received: by 2002:a05:600c:1546:b0:490:7df7:9190 with SMTP id 5b1f17b1804b1-490b0e70060mr46239885e9.8.1780389994320; Tue, 02 Jun 2026 01:46:34 -0700 (PDT) Received: from mecano.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490ab55d39csm33907625e9.35.2026.06.02.01.46.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2026 01:46:33 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 46/51] ada: Adjust translation of non-stored discriminants of tagged subtypes Date: Tue, 2 Jun 2026 10:45:34 +0200 Message-ID: <20260602084541.3829876-46-poulhies@adacore.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260602084541.3829876-1-poulhies@adacore.com> References: <20260602084541.3829876-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on 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: Eric Botcazou This changes the translation of non-stored discriminants of tagged subtypes from the (stored) discriminants of the ultimate ancestor to the (non-stored) discriminants of the tagged type, for the sake of tagged extensions. This also contains a code layout tweak to gnat_to_gnu_entity and a minor improvement to gnat_to_gnu. gcc/ada/ChangeLog: * gcc-interface/decl.cc (gnat_to_gnu_entity) : Do not repeat conditions in chained tests. (copy_and_substitute_in_layout): For a tagged subtype, inherit the non-stored dicriminants from the old type explicitely. * gcc-interface/trans.cc (gnat_to_gnu): Exclude more contexts for the transformation of boolean rvalues. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/decl.cc | 35 +++++++++++++++++++++++++++------- gcc/ada/gcc-interface/trans.cc | 2 ++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index d9b70019c4a..ff7d9bb80b4 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -3727,8 +3727,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) we are asked to output GNAT encodings, write a record that shows what we are a subtype of and also make a variable that indicates our size, if still variable. */ - if (debug_info_p - && gnat_encodings == DWARF_GNAT_ENCODINGS_ALL) + if (!debug_info_p) + ; + + else if (gnat_encodings == DWARF_GNAT_ENCODINGS_ALL) { tree gnu_subtype_marker = make_node (RECORD_TYPE); tree gnu_unpad_base_name @@ -3759,11 +3761,9 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) true, true, NULL, gnat_entity, false); } - /* Or else, if the subtype is artificial and GNAT encodings are - not used, use the base record type as the debug type. */ - else if (debug_info_p - && artificial_p - && gnat_encodings != DWARF_GNAT_ENCODINGS_ALL) + /* Or else, if the subtype is artificial, use the base record + type as the debug type. */ + else if (artificial_p) SET_TYPE_DEBUG_TYPE (gnu_type, gnu_unpad_base_type); } @@ -10975,6 +10975,27 @@ copy_and_substitute_in_layout (Entity_Id gnat_new_type, save_gnu_tree (gnat_field, gnu_field, false); } + /* For a tagged subtype, inherit the non-stored dicriminants from the old + type instead of inheriting them from an ancestor. That's specifically + helpful for the Parent_Subtype of tagged extensions when discriminants + must be rematerialized by the DWARF back-end, to describe the variant + part of extensions, because the discriminants of the old type are also + non-stored whereas those of the (ultimate) ancestor are stored. */ + if (is_subtype && Is_Tagged_Type (gnat_new_type)) + for (gnat_field = First_Discriminant (gnat_new_type); + Present (gnat_field); + gnat_field = Next_Discriminant (gnat_field)) + if (!is_stored_discriminant (gnat_field, gnat_new_type) + && (gnat_old_field = Original_Record_Component (gnat_field)) + && Underlying_Type (Scope (gnat_old_field)) == gnat_old_type + && present_gnu_tree (gnat_old_field)) + { + tree gnu_old_field = get_gnu_tree (gnat_old_field); + if (TREE_CODE (gnu_old_field) == COMPONENT_REF) + gnu_old_field = TREE_OPERAND (gnu_old_field, 1); + save_gnu_tree (gnat_field, gnu_old_field, false); + } + /* Put the fields with fixed position in order of increasing position. */ if (gnu_field_list) gnu_field_list = reverse_sort_field_list (gnu_field_list); diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index f66d0b99ba3..5140ed8bbfd 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -8780,6 +8780,8 @@ gnat_to_gnu (Node_Id gnat_node) || kind == N_Selected_Component) && TREE_CODE (get_base_type (gnu_result_type)) == BOOLEAN_TYPE && Nkind (Parent (gnat_node)) != N_Attribute_Reference + && Nkind (Parent (gnat_node)) != N_Discriminant_Association + && Nkind (Parent (gnat_node)) != N_Index_Or_Discriminant_Constraint && Nkind (Parent (gnat_node)) != N_Pragma_Argument_Association && Nkind (Parent (gnat_node)) != N_Variant_Part && !lvalue_required_p (gnat_node, gnu_result_type, false, false))