From patchwork Mon Oct 11 13:39:56 2021 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: 1539342 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=m6uQcJqP; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HSgYn18Qyz9sPB for ; Tue, 12 Oct 2021 01:05:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1A0C385803B for ; Mon, 11 Oct 2021 14:05:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1A0C385803B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633961146; bh=KlOX0cJlHoW7nZeAJbC6e3J/jd0mVqpIq+fyAm+zc8A=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=m6uQcJqPMIqz9joH1R0GMTAIpS3+1QHSS4it+hk9siOQ6MoSDmLrkYb/ayGqgXSgO g8kjCoh+5JncSxEvFLG/JxkIAqD+SdTySTlRq3JQk4B3W1TPZIPG5BmivLg6tjcI2p nXMMaIS1DyL2c9u7wmiE6Yp9N7gi7YnW+QqecvRc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 38448385803D for ; Mon, 11 Oct 2021 13:40:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 38448385803D Received: by mail-lf1-x136.google.com with SMTP id j5so74061853lfg.8 for ; Mon, 11 Oct 2021 06:40:02 -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=KlOX0cJlHoW7nZeAJbC6e3J/jd0mVqpIq+fyAm+zc8A=; b=Yx6f6SfxJLAnh1NIpaTp8M5BxRs7SktvfHi3Q2CqKa/GsKqCPjYA62RUrmtqoBGRkU pPOcdm7nL7etCEAapH+UoUvCe7xtVP1wHrsgDL7KdDyYCjHEgNG2rdjj4wkLqglqt6Vy A1LHepKtn/+TIXE0z48H67VBl96yNp8/uxqd4OMaYND48o/w8Vvt6eT1hg62YeoEUOD2 NtrSfZ0g/no5dsashF8Z5En4JScF9Z2GO0Upqpb3Z44VtmPRjd59bMIpNEhOnX/8HA97 Uiq9j7QGy6fm2cMr/Z+OAxPqCopdytVd17vTNtotxUo2CeU/oUkGT17LyfBf1QqmXyKC ha4A== X-Gm-Message-State: AOAM530zOMfAp2JeRWnJDlEi188jG7rX7yH4aB4M3ywut814q3gIO8mb FvDb0mvKwZqS3saYcMX+sxfO8SsiKh8ULQ== X-Google-Smtp-Source: ABdhPJyJB0BNRNkUd0hV4bpWGW858w3mf+leeceEvwddhvGGFY6sGaMGRx7+t9mAU79OuyVZLoSaTg== X-Received: by 2002:a2e:a415:: with SMTP id p21mr357434ljn.384.1633959599015; Mon, 11 Oct 2021 06:39:59 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id y8sm794868lfh.170.2021.10.11.06.39.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Oct 2021 06:39:58 -0700 (PDT) Date: Mon, 11 Oct 2021 13:39:56 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix for atomic wrongly rejected on object of discriminated type Message-ID: <20211011133956.GA1519188@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 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.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: , 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The reason is that the automatic alignment promotion is not yet performed in the case where the nominal subtype is of variable size. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/decl.c (promote_object_alignment): Add GNU_SIZE parameter and use it for the size of the object if not null. (gnat_to_gnu_entity) : Perform the automatic alignment promotion for objects whose nominal subtype is of variable size. (gnat_to_gnu_field): Adjust call to promote_object_alignment. diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -239,7 +239,7 @@ static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool, const char *, const char *); static void set_rm_size (Uint, tree, Entity_Id); static unsigned int validate_alignment (Uint, Entity_Id, unsigned int); -static unsigned int promote_object_alignment (tree, Entity_Id); +static unsigned int promote_object_alignment (tree, tree, Entity_Id); static void check_ok_for_atomic_type (tree, Entity_Id, bool); static tree create_field_decl_from (tree, tree, tree, tree, tree, vec); @@ -897,7 +897,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) or a reference to another object, and the size of its type is a constant, set the alignment to the smallest one which is not smaller than the size, with an appropriate cap. */ - if (!gnu_size && align == 0 + if (!Known_Esize (gnat_entity) + && !Known_Alignment (gnat_entity) && (Is_Full_Access (gnat_entity) || (!Optimize_Alignment_Space (gnat_entity) && kind != E_Exception @@ -908,8 +909,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) && !imported_p && No (gnat_renamed_obj) && No (Address_Clause (gnat_entity)))) - && TREE_CODE (TYPE_SIZE (gnu_type)) == INTEGER_CST) - align = promote_object_alignment (gnu_type, gnat_entity); + && (TREE_CODE (TYPE_SIZE (gnu_type)) == INTEGER_CST || gnu_size)) + align = promote_object_alignment (gnu_type, gnu_size, gnat_entity); /* If the object is set to have atomic components, find the component type and validate it. @@ -7322,7 +7323,7 @@ gnat_to_gnu_field (Entity_Id gnat_field, tree gnu_record_type, int packed, if (Is_Full_Access (gnat_field)) { const unsigned int align - = promote_object_alignment (gnu_field_type, gnat_field); + = promote_object_alignment (gnu_field_type, NULL_TREE, gnat_field); if (align > 0) gnu_field_type = maybe_pad_type (gnu_field_type, NULL_TREE, align, gnat_field, @@ -9393,11 +9394,11 @@ validate_alignment (Uint alignment, Entity_Id gnat_entity, unsigned int align) return align; } -/* Promote the alignment of GNU_TYPE corresponding to GNAT_ENTITY. Return - a positive value on success or zero on failure. */ +/* Promote the alignment of GNU_TYPE for an object with GNU_SIZE corresponding + to GNAT_ENTITY. Return a positive value on success or zero on failure. */ static unsigned int -promote_object_alignment (tree gnu_type, Entity_Id gnat_entity) +promote_object_alignment (tree gnu_type, tree gnu_size, Entity_Id gnat_entity) { unsigned int align, size_cap, align_cap; @@ -9418,14 +9419,17 @@ promote_object_alignment (tree gnu_type, Entity_Id gnat_entity) align_cap = get_mode_alignment (ptr_mode); } + if (!gnu_size) + gnu_size = TYPE_SIZE (gnu_type); + /* Do the promotion within the above limits. */ - if (!tree_fits_uhwi_p (TYPE_SIZE (gnu_type)) - || compare_tree_int (TYPE_SIZE (gnu_type), size_cap) > 0) + if (!tree_fits_uhwi_p (gnu_size) + || compare_tree_int (gnu_size, size_cap) > 0) align = 0; - else if (compare_tree_int (TYPE_SIZE (gnu_type), align_cap) > 0) + else if (compare_tree_int (gnu_size, align_cap) > 0) align = align_cap; else - align = ceil_pow2 (tree_to_uhwi (TYPE_SIZE (gnu_type))); + align = ceil_pow2 (tree_to_uhwi (gnu_size)); /* But make sure not to under-align the object. */ if (align <= TYPE_ALIGN (gnu_type))