From patchwork Tue Feb 27 03:12:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 86414 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 433A53858C56 for ; Tue, 27 Feb 2024 03:14:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from omta040.useast.a.cloudfilter.net (omta040.useast.a.cloudfilter.net [44.202.169.39]) by sourceware.org (Postfix) with ESMTPS id AD00E3858C98 for ; Tue, 27 Feb 2024 03:13:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AD00E3858C98 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AD00E3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709003585; cv=none; b=ksuDNyn6ZELygcR7Dc4MOIV3JcQ7bUOsHVXrHVRzjTLXlI6bTgM/wpp80w5zU6fR+a4l3QzeOWgdcHpoBIk9ZMxnUVQbkww2pMqzFtbvy8AUo8ZAEPF5WZEQAZhPGJWj5DsvU2h/HKFUfcqRV5HfQMxhEU701o2ZXoBLKFOcMTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709003585; c=relaxed/simple; bh=p6y5zFtA5UM9AHSQpwf+jnXKSd8cRiuicJkxwDsPaTc=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=jB9W6YvzMoFZoOJrcQaN7MKyw3R5LYMIwCXvfYtS2JP5JHxHuPIEJ/5I8eRG67tzZAx0X56VSe5iG8EmdqHBuvG8moX0ettImniRplXin8/V+YKJyPQyJwvzI9E2oT9CxrLI172rvvuhH0crwf9WPRbys0NyWaglUSGuR5QM5M0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5001a.ext.cloudfilter.net ([10.0.29.139]) by cmsmtp with ESMTPS id ek2QreEHml9dRenturtPgr; Tue, 27 Feb 2024 03:13:02 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id enttrXpjtmKT3enturfN2W; Tue, 27 Feb 2024 03:13:02 +0000 X-Authority-Analysis: v=2.4 cv=f/dOBvyM c=1 sm=1 tr=0 ts=65dd533e a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=k7vzHIieQBIA:10 a=Qbun_eYptAEA:10 a=zstS-IiYAAAA:8 a=20KFwNOVAAAA:8 a=wRGsumYYegGURm0rCcgA:9 a=QEXdDO2ut3YA:10 a=4G6NA9xxw8l3yy4pmD5M:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Q2ffYDW6UhzSiY0P/psH6jjvgkv6W91nrcDIumnlI94=; b=PLFIezHxJISa8qdrfsml7KBskI gTDQsw/B62/I+7y1Ld/lvzGAGQ566PVPkidkRYfMdPTMdi30TviKgFx+E5rruMjsvW1kzg3Wngscr vhtEoeH1BE9rOmovKzSUmSHhq; Received: from 71-211-170-195.hlrn.qwest.net ([71.211.170.195]:51654 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rentt-004JgU-1t for gcc-patches@gcc.gnu.org; Mon, 26 Feb 2024 20:13:01 -0700 From: Tom Tromey Date: Mon, 26 Feb 2024 20:12:56 -0700 Subject: [PATCH 3/3] Fix PR libcc1/113977 MIME-Version: 1.0 Message-Id: <20240226-gdb-compile-align-v1-3-0f95d6435299@tromey.com> References: <20240226-gdb-compile-align-v1-0-0f95d6435299@tromey.com> In-Reply-To: <20240226-gdb-compile-align-v1-0-0f95d6435299@tromey.com> To: gcc-patches@gcc.gnu.org X-Mailer: b4 0.12.4 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 71.211.170.195 X-Source-L: No X-Exim-ID: 1rentt-004JgU-1t X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 71-211-170-195.hlrn.qwest.net ([192.168.0.21]) [71.211.170.195]:51654 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfEQjSy2ufZkV7be2wCxrYi4viknXFgNDY7Q6nyJ+C3PAqZPZKYwG0Swxi9UXy8fEXrJbHy0jIj+g0rxUaZy+1k0ugZFRO9n+MDangUb3Fqy5RxvG+5Lj gc9E/tk5YZa6Y/HcyUuozM64EEApecfW/T9V2uo90QhBSNxAIJNFHZ8Q3qRgWxxP4AOBCmhKmSbNOkiJSx1MmHbgGwjjeholZyQ= X-Spam-Status: No, score=-3022.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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+patchwork=sourceware.org@gcc.gnu.org PR libcc1/113977 points out a case where a simple expression is rejected with a compiler error message. The bug here is that gdb does not inform the plugin of the correct alignment -- in fact, there is no way to do that. This patch adds a new method to allow the alignment to be set, and bumps the C front end protocol version. It also includes some updates to various comments in 'include', done here to simplify the merge to binutils-gdb. include/ChangeLog 2024-02-26 Tom Tromey * gcc-cp-interface.h (gcc_cp_fe_context_function): Update comment. * gcc-c-interface.h (enum gcc_c_api_version) : New constant. (gcc_c_fe_context_function): Update comment. * gcc-c-fe.def (finish_record_with_alignment): New method. Update documentation. libcc1/ChangeLog 2024-02-26 Tom Tromey PR libcc1/113977 * libcc1plugin.cc (plugin_finish_record_or_union): New function. (plugin_finish_record_or_union): Rewrite. (plugin_init): Use GCC_C_FE_VERSION_2. * libcc1.cc (c_vtable): Use GCC_C_FE_VERSION_2. (gcc_c_fe_context): Check for GCC_C_FE_VERSION_2. --- include/ChangeLog | 10 ++++++++++ include/gcc-c-fe.def | 13 ++++++++++++- include/gcc-c-interface.h | 11 +++++++++-- include/gcc-cp-interface.h | 6 +++++- libcc1/ChangeLog | 9 +++++++++ libcc1/libcc1.cc | 5 +++-- libcc1/libcc1plugin.cc | 26 ++++++++++++++++++-------- 7 files changed, 66 insertions(+), 14 deletions(-) diff --git a/include/ChangeLog b/include/ChangeLog index 8bfaec6faa1..4c8b5b28039 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,13 @@ +2024-02-26 Tom Tromey + + * gcc-cp-interface.h (gcc_cp_fe_context_function): Update + comment. + * gcc-c-interface.h (enum gcc_c_api_version) : + New constant. + (gcc_c_fe_context_function): Update comment. + * gcc-c-fe.def (finish_record_with_alignment): New method. + Update documentation. + 2024-01-13 Jakub Jelinek * demangle.h (enum demangle_component_type): Add diff --git a/include/gcc-c-fe.def b/include/gcc-c-fe.def index 36a765484a7..cb7cf197525 100644 --- a/include/gcc-c-fe.def +++ b/include/gcc-c-fe.def @@ -89,7 +89,10 @@ GCC_METHOD5 (int /* bool */, build_add_field, /* After all the fields have been added to a struct or union, the struct or union type must be "finished". This does some final - cleanups in GCC. */ + cleanups in GCC. + + Note that when using GCC_C_FE_VERSION_2, it is preferable to call + finish_record_with_alignment instead. */ GCC_METHOD2 (int /* bool */, finish_record_or_union, gcc_type, /* Argument RECORD_OR_UNION_TYPE. */ @@ -220,3 +223,11 @@ GCC_METHOD2 (gcc_type, float_type, unsigned long, /* Argument SIZE_IN_BYTES. */ const char *) /* Argument BUILTIN_NAME. */ +/* New in GCC_FE_VERSION_2. Like finish_record_or_union but the caller also + supplies the alignment. If the alignment is 0, this acts identically to + finish_record_or_union. */ + +GCC_METHOD3 (int /* bool */, finish_record_with_alignment, + gcc_type, /* Argument RECORD_OR_UNION_TYPE. */ + unsigned long, /* Argument SIZE_IN_BYTES. */ + unsigned long) /* Argument ALIGNMENT. */ diff --git a/include/gcc-c-interface.h b/include/gcc-c-interface.h index feece1e38a2..700d7483a4a 100644 --- a/include/gcc-c-interface.h +++ b/include/gcc-c-interface.h @@ -45,7 +45,10 @@ enum gcc_c_api_version /* Added char_type. Added new version of int_type and float_type, deprecated int_type_v0 and float_type_v0. */ - GCC_C_FE_VERSION_1 = 1 + GCC_C_FE_VERSION_1 = 1, + + /* Added finish_record_with_alignment method. */ + GCC_C_FE_VERSION_2 = 2, }; /* Qualifiers. */ @@ -198,7 +201,11 @@ struct gcc_c_context /* The type of the initialization function. The caller passes in the desired base version and desired C-specific version. If the request can be satisfied, a compatible gcc_context object will be - returned. Otherwise, the function returns NULL. */ + returned. In particular, this may return a context object with a higher + actual version number than was requested, provided the higher version is + fully compatible. (As of GCC_C_FE_VERSION_2, this is always true.) + + Otherwise, the function returns NULL. */ typedef struct gcc_c_context *gcc_c_fe_context_function (enum gcc_base_api_version, diff --git a/include/gcc-cp-interface.h b/include/gcc-cp-interface.h index 2f950729b9b..15b911cb216 100644 --- a/include/gcc-cp-interface.h +++ b/include/gcc-cp-interface.h @@ -483,7 +483,11 @@ struct gcc_cp_context /* The type of the initialization function. The caller passes in the desired base version and desired C-specific version. If the request can be satisfied, a compatible gcc_context object will be - returned. Otherwise, the function returns NULL. */ + returned. In particular, this may return a context object with a higher + actual version number than was requested, provided the higher version is + fully compatible. + + Otherwise, the function returns NULL. */ typedef struct gcc_cp_context *gcc_cp_fe_context_function (enum gcc_base_api_version, diff --git a/libcc1/ChangeLog b/libcc1/ChangeLog index b4072574ba8..a23130bac15 100644 --- a/libcc1/ChangeLog +++ b/libcc1/ChangeLog @@ -1,3 +1,12 @@ +2024-02-26 Tom Tromey + + PR libcc1/113977 + * libcc1plugin.cc (plugin_finish_record_or_union): New function. + (plugin_finish_record_or_union): Rewrite. + (plugin_init): Use GCC_C_FE_VERSION_2. + * libcc1.cc (c_vtable): Use GCC_C_FE_VERSION_2. + (gcc_c_fe_context): Check for GCC_C_FE_VERSION_2. + 2024-02-26 Tom Tromey * libcp1.cc (libcp1::libcp1): Use FE version number from context. diff --git a/libcc1/libcc1.cc b/libcc1/libcc1.cc index 992181e8fdc..1c570f3054d 100644 --- a/libcc1/libcc1.cc +++ b/libcc1/libcc1.cc @@ -108,7 +108,7 @@ set_callbacks (struct gcc_c_context *s, static const struct gcc_c_fe_vtable c_vtable = { - GCC_C_FE_VERSION_1, + GCC_C_FE_VERSION_2, set_callbacks, #define GCC_METHOD0(R, N) \ @@ -165,7 +165,8 @@ gcc_c_fe_context (enum gcc_base_api_version base_version, enum gcc_c_api_version c_version) { if ((base_version != GCC_FE_VERSION_0 && base_version != GCC_FE_VERSION_1) - || (c_version != GCC_C_FE_VERSION_0 && c_version != GCC_C_FE_VERSION_1)) + || (c_version != GCC_C_FE_VERSION_0 && c_version != GCC_C_FE_VERSION_1 + && c_version != GCC_C_FE_VERSION_2)) return NULL; return new libcc1 (&c_vtable); diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc index f1082d8e9d3..72d17c3b81c 100644 --- a/libcc1/libcc1plugin.cc +++ b/libcc1/libcc1plugin.cc @@ -387,9 +387,10 @@ plugin_build_add_field (cc1_plugin::connection *, } int -plugin_finish_record_or_union (cc1_plugin::connection *, - gcc_type record_or_union_type_in, - unsigned long size_in_bytes) +plugin_finish_record_with_alignment (cc1_plugin::connection *, + gcc_type record_or_union_type_in, + unsigned long size_in_bytes, + unsigned long align) { tree record_or_union_type = convert_in (record_or_union_type_in); @@ -407,10 +408,10 @@ plugin_finish_record_or_union (cc1_plugin::connection *, } else { - // FIXME there's no way to get this from DWARF, - // or even, it seems, a particularly good way to deduce it. - SET_TYPE_ALIGN (record_or_union_type, - TYPE_PRECISION (pointer_sized_int_node)); + if (align == 0) + align = TYPE_PRECISION (pointer_sized_int_node); + + SET_TYPE_ALIGN (record_or_union_type, align); TYPE_SIZE (record_or_union_type) = bitsize_int (size_in_bytes * BITS_PER_UNIT); @@ -441,6 +442,15 @@ plugin_finish_record_or_union (cc1_plugin::connection *, return 1; } +int +plugin_finish_record_or_union (cc1_plugin::connection *conn, + gcc_type record_or_union_type_in, + unsigned long size_in_bytes) +{ + return plugin_finish_record_with_alignment (conn, record_or_union_type_in, + size_in_bytes, 0); +} + gcc_type plugin_build_enum_type (cc1_plugin::connection *self, gcc_type underlying_int_type_in) @@ -755,7 +765,7 @@ int plugin_init (struct plugin_name_args *plugin_info, struct plugin_gcc_version *) { - generic_plugin_init (plugin_info, GCC_C_FE_VERSION_1); + generic_plugin_init (plugin_info, GCC_C_FE_VERSION_2); register_callback (plugin_info->base_name, PLUGIN_PRAGMAS, plugin_init_extra_pragmas, NULL);