From patchwork Mon Sep 23 07:46:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1165831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-509424-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="e8J2pUiZ"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46cGbg3L0Zz9sP3 for ; Mon, 23 Sep 2019 17:46:21 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=xkd7Z9Zu5CoJ984a C8BWvXBWYZCJ9RX+hxWraF9UptTl1WAdpJ4Zqt9xeeDa3k3qvGRSh4C6HlmMPPBz ytfDzv8ehwDpG97gcWWiLYLCAmjbfeRzalSqeIXyVupfhRnxQDJw+asKCK2/Xk6Z cjrM35kktXW5XjEqZSqLWK9YKks= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=VhQkvvp1uHW2d6BaL6nRFg FhTO8=; b=e8J2pUiZ4i2myNABSZKHDQ05qpHt6qxgg6MNYDKNzQeQiP1Gz6hGWK bHkCZpJOkyC0O8SfH28azlESkSBGnHfF8i6/IM/UojEdGkPPrGeuIKQj+lE2XSeR KJDGKHkBK2scqHTcsQiAWHkqwhIqWJ3MhfWVnC8VlJ2/MeRG8VNwk= Received: (qmail 100670 invoked by alias); 23 Sep 2019 07:46:14 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 100651 invoked by uid 89); 23 Sep 2019 07:46:13 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=manner, Space X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 23 Sep 2019 07:46:12 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id A2D2281385 for ; Mon, 23 Sep 2019 09:46:09 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9vWsAVgt6Xmh for ; Mon, 23 Sep 2019 09:46:09 +0200 (CEST) Received: from polaris.localnet (unknown [IPv6:2a01:e35:8a16:3850:1a03:73ff:fe45:373a]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 7E5FE81382 for ; Mon, 23 Sep 2019 09:46:09 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix size increase for packed record with aliased component Date: Mon, 23 Sep 2019 09:46:06 +0200 Message-ID: <130773067.boaW8Y2ydQ@polaris> MIME-Version: 1.0 This fixes a fallout of the reordering of components in record types that was enabled some time ago: the size of a packed record with an aliased component may be larger than the size that would have been given by a textual layout of the record type. Tested on x86_64-suse-linux, applied on the mainline. 2019-09-23 Eric Botcazou * gcc-interface/decl.c (components_to_record): Do not reorder fields in packed record types if they contain fixed-size fields that cannot be laid out in a packed manner. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 275988) +++ gcc-interface/decl.c (working copy) @@ -7521,6 +7521,7 @@ components_to_record (Node_Id gnat_compo bool all_rep_and_size = all_rep && TYPE_SIZE (gnu_record_type); bool variants_have_rep = all_rep; bool layout_with_rep = false; + bool has_non_packed_fixed_size_field = false; bool has_self_field = false; bool has_aliased_after_self_field = false; Entity_Id gnat_component_decl, gnat_variant_part; @@ -7577,6 +7578,10 @@ components_to_record (Node_Id gnat_compo has_self_field = true; else if (has_self_field && DECL_ALIASED_P (gnu_field)) has_aliased_after_self_field = true; + else if (!DECL_FIELD_OFFSET (gnu_field) + && !DECL_PACKED (gnu_field) + && !field_has_variable_size (gnu_field)) + has_non_packed_fixed_size_field = true; } } @@ -7868,8 +7873,9 @@ components_to_record (Node_Id gnat_compo self-referential/variable offset or misaligned. Note, in the latter case, that this can only happen in packed record types so the alignment is effectively capped to the byte for the whole record. But we don't - do it for non-packed record types if pragma Optimize_Alignment (Space) - is specified because this can prevent alignment gaps from being filled. + do it for packed record types if not all fixed-size fiels can be packed + and for non-packed record types if pragma Optimize_Alignment (Space) is + specified, because this can prevent alignment gaps from being filled. Optionally, if the layout warning is enabled, keep track of the above 4 different kinds of fields and issue a warning if some of them would be @@ -7880,8 +7886,9 @@ components_to_record (Node_Id gnat_compo const bool do_reorder = (Convention (gnat_record_type) == Convention_Ada && !No_Reordering (gnat_record_type) - && (!Optimize_Alignment_Space (gnat_record_type) - || Is_Packed (gnat_record_type)) + && !(Is_Packed (gnat_record_type) + ? has_non_packed_fixed_size_field + : Optimize_Alignment_Space (gnat_record_type)) && !debug__debug_flag_dot_r); const bool w_reorder = (Convention (gnat_record_type) == Convention_Ada