From patchwork Thu May 19 14:16:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 54231 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 1473D383D819 for ; Thu, 19 May 2022 14:42:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1473D383D819 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652971321; bh=G5PUa58cusXB/HL4LQkCH14d1MDXbXF985cZmZ2DFzQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=VEGcooQ2Vtk48oK4/Oh4mku4OTl9hv4pK2WmTxvsHEjb7yAKIWeFlpyotEdZd858I cdCdTkcWBVaALNqiBL3FED5QwujhBLhh6vV3tSm66SQwr9FnBHtRM8XYHEIr1CFLvk eE57/IisX8sLlnDWF3AVKJCKQ8uDsLhM9VyUCRGk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 5E22F383D837 for ; Thu, 19 May 2022 14:16:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E22F383D837 Received: by mail-wr1-x431.google.com with SMTP id j24so7407032wrb.1 for ; Thu, 19 May 2022 07:16:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=G5PUa58cusXB/HL4LQkCH14d1MDXbXF985cZmZ2DFzQ=; b=KP3/Kahdcw7QGIF7hLsPYZ3AelL/JaHV6AbVK7BJCb4kBbeXbTxKS9fSJRTQNPlj64 mOcYhFWRQSojiNMif4ZYF/xoWDm/u5tFTfRoBDS81XivlfO6+lF0yswTz7VS3kb7fVlf INnEN7lpRYwQgnBduoOxw25aMYdiT+CXbU8qyXUzK2dQtWf8c9AnyC3/DU4Hgp81KsRz hpEbVKLHpjuTvK38lT1m64TrpZ/LuR8T5UFs+xnVwgEDXEBAIqkEw9EFdYN5ZtRdSq6Q nyAPqsj5pHkVbpU5G+828RUS02SFzVsC3JvQaJBS+NZfNG7uwIl3pnYIBkY5Ge81VEwO 27AA== X-Gm-Message-State: AOAM532NOvYn6Dnv992JPsn9RYPp1V4o/Ph72MTL1rMQbENDBQX7bf8T 10Xues09bpv7hCCRk49+EV/peorJZ8b2Ew== X-Google-Smtp-Source: ABdhPJy1eS75IR5eomRv1qqeW5QvZdNTC8Cx/ZKHvzRTcO8gYkaEtn57/eh+jbAGtKfUge4os5CznQ== X-Received: by 2002:adf:cd10:0:b0:20c:fc40:1171 with SMTP id w16-20020adfcd10000000b0020cfc401171mr4395839wrm.586.1652969789137; Thu, 19 May 2022 07:16:29 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id u26-20020adfae5a000000b0020c5253d8f0sm5211747wrd.60.2022.05.19.07.16.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 07:16:28 -0700 (PDT) Date: Thu, 19 May 2022 14:16:27 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix internal error on unchecked union with component clauses (2) Message-ID: <20220519141627.GA3723559@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.2 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, T_SCC_BODY_TEXT_LINE 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Eric Botcazou Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" The issue arises when the unchecked union contains both a fixed part and a variant part, and is subject to a full representation clause covering all the components in all the variants, when the component clauses do not align the variant boundaries with byte boundaries consistently. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/decl.cc (components_to_record): Use NULL recursively as P_GNU_REP_LIST for the innermost variant level in the unchecked union case with a fixed part. diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -7981,6 +7981,7 @@ components_to_record (Node_Id gnat_component_list, Entity_Id gnat_record_type, tree gnu_union_type; tree this_first_free_pos, gnu_variant_list = NULL_TREE; bool union_field_needs_strict_alignment = false; + bool innermost_variant_level = true; auto_vec variant_types; vinfo_t *gnu_variant; unsigned int variants_align = 0; @@ -8026,6 +8027,19 @@ components_to_record (Node_Id gnat_component_list, Entity_Id gnat_record_type, } } + /* For an unchecked union with a fixed part, we need to compute whether + we are at the innermost level of the variant part. */ + if (unchecked_union && gnu_field_list) + for (variant = First_Non_Pragma (Variants (gnat_variant_part)); + Present (variant); + variant = Next_Non_Pragma (variant)) + if (Present (Component_List (variant)) + && Present (Variant_Part (Component_List (variant)))) + { + innermost_variant_level = false; + break; + } + /* We build the variants in two passes. The bulk of the work is done in the first pass, that is to say translating the GNAT nodes, building the container types and computing the associated properties. However @@ -8066,11 +8080,12 @@ components_to_record (Node_Id gnat_component_list, Entity_Id gnat_record_type, /* Add the fields into the record type for the variant but note that we aren't sure to really use it at this point, see below. In the - case of an unchecked union, we force the fields with a rep clause - present in a nested variant to be moved to the outermost variant, - so as to flatten the rep-ed layout as much as possible, the reason - being that we cannot do any flattening when a subtype statically - selects a variant later on, for example for an aggregate. */ + case of an unchecked union with a fixed part, we force the fields + with a rep clause present in the innermost variant to be moved to + the outer variant, so as to flatten the rep-ed layout as much as + possible, the reason being that we cannot do any flattening when + a subtype statically selects a variant later on, for example for + an aggregate. */ has_rep = components_to_record (Component_List (variant), gnat_record_type, NULL_TREE, gnu_variant_type, packed, @@ -8078,7 +8093,9 @@ components_to_record (Node_Id gnat_component_list, Entity_Id gnat_record_type, unchecked_union, true, needs_xv_encodings, true, this_first_free_pos, (all_rep || this_first_free_pos) - && !(in_variant && unchecked_union) + && !(unchecked_union + && gnu_field_list + && innermost_variant_level) ? NULL : &gnu_rep_list); /* Translate the qualifier and annotate the GNAT node. */