]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
gdb: tighten assertions in set_type_vptr_*
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 26 Jan 2026 15:54:00 +0000 (10:54 -0500)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 2 Feb 2026 18:13:09 +0000 (13:13 -0500)
commitcd3594fdb75b4d3003c3499eac41f4009bb27898
tree9e2f7e576fbe88be74aae461f40a063ad1c1ff13
parenta549af202c351ef2683101c360e57ca98953db05
gdb: tighten assertions in set_type_vptr_*

In C++, only structures and classes (represented by TYPE_CODE_STRUCT)
can participate in inheritance.  I therefore think it does not make
sense to allow for TYPE_CODE_UNION in set_type_vptr_basetype and
set_type_vptr_fieldno.  Remove the possibility for the type to be a
union in these functions.

Also, for the same reason, add an assertion that checks the type of
basetype in set_type_vptr_basetype.

I did not change the getters (internal_type_vptr_fieldno and
internal_type_vptr_basetype), because it seems like they are called by
code that handles similarly both structures and unions.  Making those
stricter would require adding conditions in those callers, which doesn't
look like an improvement.  For unions, they will correctly return an
"invalid" value.

Change allocate_cplus_struct_type to not use set_type_vptr_fieldno to
initialize the field to -1, otherwise it would trip the assertion when
initializing for a union type.

Change-Id: Id9b2dc288f24d50eb50da46782b5ec6de5682e81
Approved-by: Kevin Buettner <kevinb@redhat.com>
gdb/gdbtypes.c