From 1775f8b3804744c22611ed0c9fd2df4f5b4d8641 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Wed, 11 Jan 2023 12:42:40 -0700 Subject: Increase size of main_type::nfields main_type::nfields is a 'short', and has been for many years. PR c++/29985 points out that 'short' is too narrow for an enum that contains more than 2^15 constants. This patch bumps the size of 'nfields'. To verify that the field isn't directly used, it is also renamed. Note that this does not affect the size of main_type on x86-64 Fedora 36. And, if it does have a negative effect somewhere, it's worth considering that types could be shrunk more drastically by using subclasses for the different codes. This is v2 of this patch, which has these changes: * I changed nfields to 'unsigned', per Simon's request. I looked at changing all the uses, but this quickly fans out into a very large patch. (One additional tweak was needed, though.) * I wrote a test case. I discovered that GCC cannot compile a large enough C test case, so I resorted to using the DWARF assembler. This test doesn't reproduce the crash, but it does fail without the patch. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=29985 --- gdb/compile/compile-cplus-types.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gdb/compile') diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c index 5566115..d48aa61 100644 --- a/gdb/compile/compile-cplus-types.c +++ b/gdb/compile/compile-cplus-types.c @@ -981,7 +981,7 @@ compile_cplus_convert_func (compile_cplus_instance *instance, gcc_type return_type = instance->convert_type (target_type); std::vector elements (type->num_fields ()); - struct gcc_type_array array = { type->num_fields (), elements.data () }; + struct gcc_type_array array = { (int) type->num_fields (), elements.data () }; int artificials = 0; for (int i = 0; i < type->num_fields (); ++i) { -- cgit v1.1