From bc0e18a960f9dff3e740f4d0cb5b25b3f68d920a Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 26 Feb 2024 18:21:03 -0700 Subject: Fix PR libcc1/113977 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 * 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 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. --- libcc1/libcc1plugin.cc | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'libcc1/libcc1plugin.cc') diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc index f1082d8..72d17c3 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); -- cgit v1.1