From patchwork Thu Sep 5 08:10:55 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: 1981133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=PQ2zIYUe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzsXC2tYwz1yg7 for ; Thu, 5 Sep 2024 18:11:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8A57C386549E for ; Thu, 5 Sep 2024 08:11:53 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 1F4A8386482F for ; Thu, 5 Sep 2024 08:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F4A8386482F 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 1F4A8386482F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725523878; cv=none; b=OegNpSLobeaAZvRooL4NLPssq3SgcOtpKCggnij31yMAvSXbA9L+AR/ZzFEF2HfOkzta1n0kxPYp9VLBDxFwh/McvJStmALp50qqUz9SlgxTqv700yTU1cQeGgXZxS04UDvtLE6QUouyeam+29HwlAKvVpcfwmzo0QQmuay2w/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725523878; c=relaxed/simple; bh=3D0xoNkV1QjPg7yM5Nw6pzX5FUVJetXDl7dprCS9Tpo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=V+lSkaMjs32CkP3KiWZtd/tOPell7IsV9pZJW4YXKjQrI0pdrLoiAszt4u2TpKVEHjHiTFA0nWB2CdaK0KNRh5dpoz5h0MQEygEohPb3/tJZg2TzMOgjl5ggRoR3mDLO33V+Rc+sqLzrE1fMzdMNhKvcVGCDLOxsYU5dr/BMeMU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-42c7a49152aso4271415e9.2 for ; Thu, 05 Sep 2024 01:11:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1725523874; x=1726128674; 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=ajVrEDe9bUCvqHbiWl3XRWY75FP5fHdSQi+SvzX32Gg=; b=PQ2zIYUe+Q/ko5YzLhS6uWdPWl22Khu2cWmirGk++zwPiIkR5zrfGcoEURFfWqgFXB RP4jMBwqX1VlivESu3sp6vjReHtrenk8HIlq0XpCqu1EwzPUgA3lJfp0kNta1fcvtCFH fH51HSZ8FdhU8Fl6ih+v6+PgufPKfbMIRNM/oLVnbUG/qXg8O+XJBokSQl4D8ZnXTox5 +wjOr/Rs+0vj7cCSrfY13oMhhzEWxst4AvJTANjnWTn5bYwlsi+4DJRBlq3ojEcy0J60 7Kz9lTWldzfd1k+bOGGmm4dvU/UrrYP2mFjYUkNSZmfQjvAbK2FmEsFvsWv4Poljtmoz Dlsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725523874; x=1726128674; 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=ajVrEDe9bUCvqHbiWl3XRWY75FP5fHdSQi+SvzX32Gg=; b=gc0U/c6+/jqX4w2iwsoowQusJbdNXnDD2ERfhQJuqyKHdwbVPPAfYjGkK+p0dABHMh 7cDbj7N+V90xNPNwFaJ1TuA3tcag2Iwxz90mRfV/R4VYlOFFpv8KMeU0PGtgK64UVocY XheeaEDtsA8wj7MpvuDLBNSHCq8F9VRHmEZJTVqmzZDbzCiKy7Rpk5IgP/Gx3cgxM5H/ aFvP0oq/OvxKCbVRj7hZKdTY22wi/p6rBRbCUQa3nDbcAHwztad4VYx16AOiAnopQM44 dbMEqiJC+J8SXYjGusDcOP+ClM8jkKqiIiancEI/7TD2tBymShHZb50k+HjnJITPHPWe e/RQ== X-Gm-Message-State: AOJu0Yz8l1hP7ktttNU8HYHkvFxCnKO+K73Kd4yRKQxjFh/7QD3Ax7mz sK5fErupZSDShU6bQQB0IMGU6avK2gpgN17mBUnx2z1jYgKg11hpUqnzyZm0AmnAKTGwMn129U0 = X-Google-Smtp-Source: AGHT+IHMaIU6lO4ngI1abtwkDfddQuT83kiwyXheaNhQCpf6AV/TBed7gyyirLUWvCl2RsqtHKvMKw== X-Received: by 2002:a05:600c:6009:b0:428:e30:fa8d with SMTP id 5b1f17b1804b1-42c9a360294mr15436065e9.6.1725523873104; Thu, 05 Sep 2024 01:11:13 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42baf7fa745sm242524555e9.31.2024.09.05.01.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 01:11:12 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 5/6] ada: Streamline handling of low-level peculiarities of record field layout Date: Thu, 5 Sep 2024 10:10:55 +0200 Message-ID: <20240905081056.2402112-5-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240905081056.2402112-1-poulhies@adacore.com> References: <20240905081056.2402112-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Eric Botcazou This factors out the interface to the low-level field layout machinery. gcc/ada/ * gcc-interface/gigi.h (default_field_alignment): New function. * gcc-interface/misc.cc: Include tm_p header file. (default_field_alignment): New function. * gcc-interface/trans.cc (addressable_p) : Replace previous alignment klduge with call to default_field_alignment. * gcc-interface/utils.cc (finish_record_type): Likewise for the alignment based on which DECL_BIT_FIELD should be cleared. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/gcc-interface/gigi.h | 4 ++++ gcc/ada/gcc-interface/misc.cc | 21 +++++++++++++++++++++ gcc/ada/gcc-interface/trans.cc | 24 +++++++----------------- gcc/ada/gcc-interface/utils.cc | 2 +- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/gcc/ada/gcc-interface/gigi.h b/gcc/ada/gcc-interface/gigi.h index 40f3f0d3d13..f4b302be3e0 100644 --- a/gcc/ada/gcc-interface/gigi.h +++ b/gcc/ada/gcc-interface/gigi.h @@ -1008,6 +1008,10 @@ extern bool must_pass_by_ref (tree gnu_type); /* Return the size of the FP mode with precision PREC. */ extern int fp_prec_to_size (int prec); +/* Return the default alignment of a FIELD of TYPE declared in a record or + union type as specified by the ABI of the target architecture. */ +extern unsigned int default_field_alignment (tree field, tree type); + /* Return the precision of the FP mode with size SIZE. */ extern int fp_size_to_prec (int size); diff --git a/gcc/ada/gcc-interface/misc.cc b/gcc/ada/gcc-interface/misc.cc index 13cb39e91cb..ef5de7f5651 100644 --- a/gcc/ada/gcc-interface/misc.cc +++ b/gcc/ada/gcc-interface/misc.cc @@ -28,6 +28,7 @@ #include "coretypes.h" #include "target.h" #include "tree.h" +#include "tm_p.h" #include "diagnostic.h" #include "opts.h" #include "alias.h" @@ -1129,6 +1130,26 @@ must_pass_by_ref (tree gnu_type) && TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) != INTEGER_CST)); } +/* Return the default alignment of a FIELD of TYPE declared in a record or + union type as specified by the ABI of the target architecture. */ + +unsigned int +default_field_alignment (tree ARG_UNUSED (field), tree type) +{ + /* This is modeled on layout_decl. */ + unsigned int align = TYPE_ALIGN (type); + +#ifdef BIGGEST_FIELD_ALIGNMENT + align = MIN (align, (unsigned int) BIGGEST_FIELD_ALIGNMENT); +#endif + +#ifdef ADJUST_FIELD_ALIGN + align = ADJUST_FIELD_ALIGN (field, type, align); +#endif + + return align; +} + /* This function is called by the front-end to enumerate all the supported modes for the machine, as well as some predefined C types. F is a function which is called back with the parameters as listed below, first a string, diff --git a/gcc/ada/gcc-interface/trans.cc b/gcc/ada/gcc-interface/trans.cc index c99b06670d5..9e9f5f8dcba 100644 --- a/gcc/ada/gcc-interface/trans.cc +++ b/gcc/ada/gcc-interface/trans.cc @@ -10291,23 +10291,13 @@ addressable_p (tree gnu_expr, tree gnu_type) /* Even with DECL_BIT_FIELD cleared, we have to ensure that the field is sufficiently aligned, in case it is subject to a pragma Component_Alignment. But we don't need to - check the alignment of the containing record, as it is - guaranteed to be not smaller than that of its most - aligned field that is not a bit-field. */ - && (DECL_ALIGN (TREE_OPERAND (gnu_expr, 1)) - >= TYPE_ALIGN (TREE_TYPE (gnu_expr)) -#ifdef TARGET_ALIGN_DOUBLE - /* Cope with the misalignment of doubles in records for - ancient 32-bit ABIs like that of x86/Linux. */ - || (DECL_ALIGN (TREE_OPERAND (gnu_expr, 1)) == 32 - && TYPE_ALIGN (TREE_TYPE (gnu_expr)) == 64 - && !TARGET_ALIGN_DOUBLE -#ifdef TARGET_64BIT - && !TARGET_64BIT -#endif - ) -#endif - )) + check the alignment of the containing record, since it + is guaranteed to be not smaller than that of its most + aligned field that is not a bit-field. However, we need + to cope with quirks of ABIs that may misalign fields. */ + && DECL_ALIGN (TREE_OPERAND (gnu_expr, 1)) + >= default_field_alignment (TREE_OPERAND (gnu_expr, 1), + TREE_TYPE (gnu_expr))) /* The field of a padding record is always addressable. */ || TYPE_IS_PADDING_P (TREE_TYPE (TREE_OPERAND (gnu_expr, 0)))) && addressable_p (TREE_OPERAND (gnu_expr, 0), NULL_TREE)); diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index 66e3192ea4f..60f36b1e50d 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -2220,7 +2220,7 @@ finish_record_type (tree record_type, tree field_list, int rep_level, if (DECL_BIT_FIELD (field) && operand_equal_p (this_size, TYPE_SIZE (type), 0)) { - const unsigned int align = TYPE_ALIGN (type); + const unsigned int align = default_field_alignment (field, type); /* In the general case, type alignment is required. */ if (value_factor_p (pos, align))