From: Tom Tromey Date: Mon, 26 Aug 2024 17:30:01 +0000 (-0600) Subject: Move enum size check into ada_identical_enum_types_p X-Git-Tag: gdb-16-branchpoint~937 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bf0419eea579e0b4a8935be91f34e6871263096;p=thirdparty%2Fbinutils-gdb.git Move enum size check into ada_identical_enum_types_p Currently, the callers of ada_identical_enum_types_p must check that both enum types have the same number of members. In another series I'm working on, it was convenient to move this check into the callee instead; and I broke this patch out to make that series a little simpler. Approved-By: Tom de Vries --- diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 57f2b2bb9a7..0f7100dfc94 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -3814,8 +3814,6 @@ ada_resolve_enum (std::vector &syms, for (int i = 0; i < syms.size (); ++i) { struct type *type2 = ada_check_typedef (syms[i].symbol->type ()); - if (type1->num_fields () != type2->num_fields ()) - continue; if (strcmp (type1->name (), type2->name ()) != 0) continue; if (ada_identical_enum_types_p (type1, type2)) @@ -4970,8 +4968,7 @@ is_nondebugging_type (struct type *type) that are deemed "identical" for practical purposes. This function assumes that TYPE1 and TYPE2 are both TYPE_CODE_ENUM - types and that their number of enumerals is identical (in other - words, type1->num_fields () == type2->num_fields ()). */ + types. */ static bool ada_identical_enum_types_p (struct type *type1, struct type *type2) @@ -4981,6 +4978,9 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2) number of enumerals and that all enumerals have the same underlying value and name. */ + if (type1->num_fields () != type2->num_fields ()) + return false; + /* All enums in the type should have an identical underlying value. */ for (int i = 0; i < type1->num_fields (); i++) if (type1->field (i).loc_enumval () != type2->field (i).loc_enumval ()) @@ -5046,12 +5046,6 @@ symbols_are_identical_enums (const std::vector &syms) if (syms[i].symbol->value_longest () != syms[0].symbol->value_longest ()) return 0; - /* Quick check: They should all have the same number of enumerals. */ - for (i = 1; i < syms.size (); i++) - if (syms[i].symbol->type ()->num_fields () - != syms[0].symbol->type ()->num_fields ()) - return 0; - /* All the sanity checks passed, so we might have a set of identical enumeration types. Perform a more complete comparison of the type of each symbol. */