From: Dodji Seketeli Date: Thu, 20 Jun 2019 16:04:43 +0000 (+0200) Subject: Fully account for anonymous-ness of scopes when comparing decl names X-Git-Tag: libabigail-1.7~79 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=bf100fcb4169d6b66e6727932c2c3323c549744a;p=libabigail.git Fully account for anonymous-ness of scopes when comparing decl names When comparing internal decl names (as part of decl comparison), we need to take into account the fact that a given decl might be anonymous and that it might have anonymous scopes in its tree of containing scopes. For instance, "__anonymous_struct__1::foo" and "__anonymous_struct__2::foo" are considered equivalent. So are "__anonymous_struct__1::foo::__anonymous_struct__2::bar" and "__anonymous_struct__10::foo::__anonymous_struct__11::bar". But "__anonymous_struct__1::bar::__anonymous_struct__2::baz" and "__anonymous_struct__10::foo::__anonymous_struct__11::bar" are not. This patch introduces the function tools_utils::decl_names_equal that compares fully qualified names by taking into account anonymous component names. That function is thus used in the equals() function overload for decl_base types. Because tools_utils::decl_names_equal compares strings the usual way (character by character) it's slower than comparing instances of interned_string in a O(1) time. So the patch carefully tries to use tools_utils::decl_names_equal sparringly; that is, it uses it only when we are looking at decls that have some anonymous scope. That way, we use the fast interned_string comparison most of the time. By doing this, we barely see any performance degradation while running abidw --noout on a full blown vmlinux binary. * include/abg-ir.h (decl_base::{get_has_anonymous_parent, set_has_anonymous_parent, get_is_anonymous_or_has_anonymous_parent}): Declare new member functions. * src/abg-ir.cc (decl_base::priv::has_anonymous_parent_): Define new data member. (decl_base::priv): Initialize the new data member. (decl_base::{get_has_anonymous_parent, set_has_anonymous_parent, get_is_anonymous_or_has_anonymous_parent}): Define new member functions. (equals): In the overload for decl_base, use the new decl_names_equal for decls that have anonymous scopes. (scope_decl::add_member_decl): Propagate the decl_base::has_anonymous_parent_ property. * include/abg-tools-utils.h (get_anonymous_struct_internal_name_prefix) (get_anonymous_union_internal_name_prefix) (get_anonymous_enum_internal_name_prefix, decl_names_equal): Declare new functions. * src/abg-comp-filter.cc (has_harmless_name_change): Handle the case where the name change is actually from an anonymous name to another one, using the new decl_names_equal function. * src/abg-dwarf-reader.cc (get_internal_anonymous_die_prefix_name): Renamed get_internal_anonynous_die_base_name into this. Use the new get_anonymous_{struct, union, enum}_internal_name_prefix functions here. (get_internal_anonymous_die_name, die_qualified_type_name) (build_enum_type, add_or_update_class_type) (add_or_update_union_type): Adjust. * src/abg-tools-utils.cc (get_anonymous_struct_internal_name_prefix) (get_anonymous_union_internal_name_prefix) (get_anonymous_enum_internal_name_prefix, decl_names_equal): Define new functions. * tests/test-tools-utils.cc: New test file. * tests/Makefile.am: Add new runtesttoolsutils test, built from test-tools-utils.cc. * tests/data/test-diff-dwarf/test46-rust-report-0.txt: Adjust. * tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt: Likewise. * tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise. Signed-off-by: Dodji Seketeli --- diff --git a/include/abg-ir.h b/include/abg-ir.h index b3616e0c..de7ae0c2 100644 --- a/include/abg-ir.h +++ b/include/abg-ir.h @@ -1371,6 +1371,15 @@ public: void set_is_anonymous(bool); + bool + get_has_anonymous_parent() const; + + void + set_has_anonymous_parent(bool f) const; + + bool + get_is_anonymous_or_has_anonymous_parent() const; + const interned_string& get_linkage_name() const; diff --git a/include/abg-tools-utils.h b/include/abg-tools-utils.h index 4181bf0f..3eb71cb7 100644 --- a/include/abg-tools-utils.h +++ b/include/abg-tools-utils.h @@ -42,11 +42,16 @@ using std::set; using std::tr1::shared_ptr; const char* get_system_libdir(); +const char* get_anonymous_struct_internal_name_prefix(); +const char* get_anonymous_union_internal_name_prefix(); +const char* get_anonymous_enum_internal_name_prefix(); + bool file_exists(const string&); bool is_regular_file(const string&); bool is_dir(const string&); bool dir_exists(const string&); bool dir_is_empty(const string &); +bool decl_names_equal(const string&, const string&); bool maybe_get_symlink_target_file_path(const string& file_path, string& target_path); bool base_name(string const& path, diff --git a/src/abg-comp-filter.cc b/src/abg-comp-filter.cc index 6d9c592a..ed099c16 100644 --- a/src/abg-comp-filter.cc +++ b/src/abg-comp-filter.cc @@ -30,6 +30,7 @@ ABG_BEGIN_EXPORT_DECLARATIONS #include "abg-comp-filter.h" +#include "abg-tools-utils.h" ABG_END_EXPORT_DECLARATIONS // @@ -423,6 +424,13 @@ has_harmless_name_change(const decl_base_sptr& f, const decl_base_sptr& s) && (// ... an anonymous decl name changed into another // anonymous decl name ... (f->get_is_anonymous() && s->get_is_anonymous()) + || + // ... an anonymous decl name changed harmlessly into + // another anonymous decl name ... + ((f->get_is_anonymous_or_has_anonymous_parent() + && s->get_is_anonymous_or_has_anonymous_parent()) + && tools_utils::decl_names_equal(f->get_qualified_name(), + s->get_qualified_name())) // ... a typedef name change, without having the // underlying type changed ... || (is_typedef(f) diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc index 76aa6690..8cf6eeb8 100644 --- a/src/abg-dwarf-reader.cc +++ b/src/abg-dwarf-reader.cc @@ -432,7 +432,7 @@ die_die_attribute(const Dwarf_Die* die, bool look_thru_abstract_origin = true); static string -get_internal_anonynous_die_base_name(const Dwarf_Die *die); +get_internal_anonymous_die_prefix_name(const Dwarf_Die *die); static string build_internal_anonymous_die_name(const string &base_name, @@ -11132,7 +11132,7 @@ is_anonymous_type_die(Dwarf_Die *die) /// @return a string representing the base of the internal anonymous /// name. static string -get_internal_anonynous_die_base_name(const Dwarf_Die *die) +get_internal_anonymous_die_prefix_name(const Dwarf_Die *die) { ABG_ASSERT(die_is_type(die)); ABG_ASSERT(die_string_attribute(die, DW_AT_name) == ""); @@ -11140,11 +11140,11 @@ get_internal_anonynous_die_base_name(const Dwarf_Die *die) int tag = dwarf_tag(const_cast(die)); string type_name; if (tag == DW_TAG_class_type || tag == DW_TAG_structure_type) - type_name = "__anonymous_struct__"; + type_name = tools_utils::get_anonymous_struct_internal_name_prefix(); else if (tag == DW_TAG_union_type) - type_name = "__anonymous_union__"; + type_name = tools_utils::get_anonymous_union_internal_name_prefix(); else if (tag == DW_TAG_enumeration_type) - type_name = "__anonymous_enum__"; + type_name = tools_utils::get_anonymous_enum_internal_name_prefix(); return type_name; } @@ -11152,7 +11152,7 @@ get_internal_anonynous_die_base_name(const Dwarf_Die *die) /// Build a full internal anonymous type name. /// /// @param base_name this is the base name as returned by the function -/// @ref get_internal_anonynous_die_base_name. +/// @ref get_internal_anonymous_die_prefix_name. /// /// @param anonymous_type_index this is the index of the anonymous /// type in its scope. That is, if there are more than one anonymous @@ -11190,7 +11190,7 @@ static string get_internal_anonymous_die_name(Dwarf_Die *die, size_t anonymous_type_index) { - string name = get_internal_anonynous_die_base_name(die); + string name = get_internal_anonymous_die_prefix_name(die); name = build_internal_anonymous_die_name(name, anonymous_type_index); return name; } @@ -11280,7 +11280,7 @@ die_qualified_type_name(const read_context& ctxt, // that case, their name must be built with the function // get_internal_anonymous_die_name or something of the same // kind. - name = get_internal_anonynous_die_base_name(die); + name = get_internal_anonymous_die_prefix_name(die); ABG_ASSERT(!name.empty()); repr = parent_name.empty() ? name : parent_name + separator + name; @@ -13721,7 +13721,7 @@ build_enum_type(read_context& ctxt, // If the enum is anonymous, let's give it a name. if (name.empty()) { - name = get_internal_anonynous_die_base_name(die); + name = get_internal_anonymous_die_prefix_name(die); ABG_ASSERT(!name.empty()); // But we remember that the type is anonymous. enum_is_anonymous = true; @@ -14232,7 +14232,7 @@ add_or_update_class_type(read_context& ctxt, { // So we are looking at an anonymous struct. Let's // give it a name. - name = get_internal_anonynous_die_base_name(die); + name = get_internal_anonymous_die_prefix_name(die); ABG_ASSERT(!name.empty()); // But we remember that the type is anonymous. is_anonymous = true; @@ -14581,7 +14581,7 @@ add_or_update_union_type(read_context& ctxt, { // So we are looking at an anonymous union. Let's give it a // name. - name = get_internal_anonynous_die_base_name(die); + name = get_internal_anonymous_die_prefix_name(die); ABG_ASSERT(!name.empty()); // But we remember that the type is anonymous. is_anonymous = true; diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 59b31c5a..9d4ed28a 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -2882,6 +2882,7 @@ struct decl_base::priv { bool in_pub_sym_tab_; bool is_anonymous_; + bool has_anonymous_parent_; location location_; context_rel *context_; interned_string name_; @@ -2908,6 +2909,7 @@ struct decl_base::priv priv() : in_pub_sym_tab_(false), is_anonymous_(true), + has_anonymous_parent_(false), context_(), visibility_(VISIBILITY_DEFAULT) {} @@ -2923,11 +2925,13 @@ struct decl_base::priv visibility_(vis) { is_anonymous_ = name_.empty(); + has_anonymous_parent_ = false; } priv(const location& l) : in_pub_sym_tab_(false), is_anonymous_(true), + has_anonymous_parent_(false), location_(l), context_(), visibility_(VISIBILITY_DEFAULT) @@ -3177,6 +3181,34 @@ void decl_base::set_is_anonymous(bool f) {priv_->is_anonymous_ = f;} +/// Get the "has_anonymous_parent" flag of the current declaration. +/// +/// Having an anoymous parent means having a anonymous parent scope +/// (containing type or namespace) which is either direct or indirect. +/// +/// @return true iff the current decl has a direct or indirect scope +/// which is anonymous. +bool +decl_base::get_has_anonymous_parent() const +{return priv_->has_anonymous_parent_;} + +/// Set the "has_anonymous_parent" flag of the current declaration. +/// +/// Having an anoymous parent means having a anonymous parent scope +/// (containing type or namespace) which is either direct or indirect. +/// +/// @param f set the flag which says if the current decl has a direct +/// or indirect scope which is anonymous. +void +decl_base::set_has_anonymous_parent(bool f) const +{priv_->has_anonymous_parent_ = f;} + +/// @return the logical "OR" of decl_base::get_is_anonymous() and +/// decl_base::get_has_anonymous_parent(). +bool +decl_base::get_is_anonymous_or_has_anonymous_parent() const +{return get_is_anonymous() || get_has_anonymous_parent();} + /// Getter for the mangled name. /// /// @return the new mangled name. @@ -3372,58 +3404,36 @@ equals(const decl_base& l, const decl_base& r, change_kind* k) } } - // This is the name of the decls that we want to compare. The kind - // of name we want to consider depends on if the containing scopes - // are anonymous or not. - interned_string ln = l.get_scoped_name(), rn = r.get_scoped_name(); - scope_decl *lscope = l.get_scope(), *rscope = r.get_scope(); + // This is the name of the decls that we want to compare. + interned_string ln = l.get_qualified_name(), rn = r.get_qualified_name(); - /// If the current decl is anonymous, let's consider its scope - /// instead. If the scope is anonymous as well, then we won't - /// consider it. + /// If both of the current decls have an anonymous scope then let's + /// compare their name component by component by properly handling + /// anonyous scopes. That's the slow path. /// - /// TODO: Ideally, we'll compare the fully qualified names of the - /// decls, comparing them component by component. Whenever two - /// components are anonymous, don't compare them. - if (l.get_is_anonymous()) - { - if (lscope && lscope->get_is_anonymous()) - ln.clear(); - else if (lscope) - ln = lscope->get_name(); - } - else - { - if (lscope && lscope->get_is_anonymous()) - ln = l.get_name(); - } - - if (r.get_is_anonymous()) - { - if (rscope && rscope->get_is_anonymous()) - rn.clear(); - else if (rscope) - rn = rscope->get_name(); - } - else - { - if (rscope && rscope->get_is_anonymous()) - rn = r.get_name(); - } - - if (// If the two scopes are anonymous then only consider the name - // of the decl, not its scope name. This is because the two - // scope (internal) names might be different even though they - // are both anonymous. In that case, the internal name of the - // scope is irrelevant so we want to ignore it. - lscope && lscope->get_is_anonymous() - && rscope && rscope->get_is_anonymous()) - { - ln = l.get_name(); - rn = r.get_name(); - } - - if (ln != rn) + /// Otherwise, let's just compare their name, the obvious way. + /// That's the fast path because in that case the names are + /// interned_string and comparing them is much faster. + bool decls_are_different = (ln != rn); + if (decls_are_different + && l.get_is_anonymous() + && !l.get_has_anonymous_parent() + && r.get_is_anonymous() + && !r.get_has_anonymous_parent()) + // Both decls are anonymous and their scope are *NOT* anonymous. + // So we consider the decls to have equivalent names (both + // anonymous, remember). We are still in the fast path here. + decls_are_different = false; + + if (decls_are_different + && l.get_has_anonymous_parent() + && r.get_has_anonymous_parent()) + // This is the slow path as we are comparing the decl qualified + // names component by component, properly handling anonymous + // scopes. + decls_are_different = tools_utils::decl_names_equal(ln, rn); + + if (decls_are_different) { result = false; if (k) @@ -5227,6 +5237,11 @@ scope_decl::add_member_decl(const decl_base_sptr& member) update_qualified_name(member); + // Propagate scope anonymity + if (get_has_anonymous_parent() + || (!is_global_scope(this) && get_is_anonymous())) + member->set_has_anonymous_parent(true); + if (const environment* env = get_environment()) set_environment_for_artifact(member, env); diff --git a/src/abg-tools-utils.cc b/src/abg-tools-utils.cc index 5645a093..1605245e 100644 --- a/src/abg-tools-utils.cc +++ b/src/abg-tools-utils.cc @@ -294,6 +294,131 @@ is_dir(const string& path) return false; } +static const char* ANONYMOUS_STRUCT_INTERNAL_NAME = "__anonymous_struct__"; +static const char* ANONYMOUS_UNION_INTERNAL_NAME = "__anonymous_union__"; +static const char* ANONYMOUS_ENUM_INTERNAL_NAME = "__anonymous_enum__"; + +static int ANONYMOUS_STRUCT_INTERNAL_NAME_LEN = + strlen(ANONYMOUS_STRUCT_INTERNAL_NAME); + +static int ANONYMOUS_UNION_INTERNAL_NAME_LEN = + strlen(ANONYMOUS_UNION_INTERNAL_NAME); + +static int ANONYMOUS_ENUM_INTERNAL_NAME_LEN = + strlen(ANONYMOUS_ENUM_INTERNAL_NAME); + +/// Getter of the prefix for the name of anonymous structs. +/// +/// @reaturn the prefix for the name of anonymous structs. +const char* +get_anonymous_struct_internal_name_prefix() +{return ANONYMOUS_STRUCT_INTERNAL_NAME;} + +/// Getter of the prefix for the name of anonymous unions. +/// +/// @reaturn the prefix for the name of anonymous unions. +const char* +get_anonymous_union_internal_name_prefix() +{return ANONYMOUS_UNION_INTERNAL_NAME;} + +/// Getter of the prefix for the name of anonymous enums. +/// +/// @reaturn the prefix for the name of anonymous enums. +const char* +get_anonymous_enum_internal_name_prefix() +{return ANONYMOUS_ENUM_INTERNAL_NAME;} + +/// Compare two fully qualified decl names by taking into account that +/// they might have compontents that are anonymous types/namespace names. +/// +/// For instance: +/// +/// __anonymous_struct__1::foo and __anonymous_struct__2::foo are +/// considered being equivalent qualified names because both are data +/// members that belong to anonymous structs. The anonymous structs +/// are numbered so that we can tell them appart (and look them up) +/// where there are several of them in the same scope. But during +/// comparison, for various purposes, we want to consider them as +/// equivalent. +/// +/// Similarly, __anonymous_struct__1::foo::__anonymous_struct__2::bar +/// and __anonymous_struct__10::foo::__anonymous_struct__11::bar are +/// equivalent. +/// +/// But __anonymous_struct__1::foo::__anonymous_struct__2::bar and +/// __anonymous_struct__10::foo::__anonymous_union__11::bar are not +/// equivalent because the former designates a member of an anonymous +/// struct and the latter designates a member of an anonymous union. +/// +/// So this function handles those cases. +/// +/// @param l the name of the first (left hand side) decl to consider. +/// +/// @param r the name of the second (right hand side) decl to consider. +/// +/// @return true iff @p l is equivalent to @p r when taking into +/// account the anonymous scopes that both might have and if they +/// might be anonymous themselves. +bool +decl_names_equal(const string& l, const string& r) +{ + string::size_type l_pos1 = 0, l_pos2 = 0, r_pos1 = 0, r_pos2 = 0; + string::size_type l_length = l.length(), r_length = r.length(); + + while (l_pos1 < l_length && r_pos1 < r_length) + { + l_pos2 = l.find("::", l_pos1); + r_pos2 = r.find("::", r_pos1); + + if ((l.compare(l_pos1, + ANONYMOUS_STRUCT_INTERNAL_NAME_LEN, + ANONYMOUS_STRUCT_INTERNAL_NAME) == 0 + && r.compare(r_pos1, + ANONYMOUS_STRUCT_INTERNAL_NAME_LEN, + ANONYMOUS_STRUCT_INTERNAL_NAME) == 0) + || + (l.compare(l_pos1, + ANONYMOUS_UNION_INTERNAL_NAME_LEN, + ANONYMOUS_UNION_INTERNAL_NAME) == 0 + && r.compare(r_pos1, + ANONYMOUS_UNION_INTERNAL_NAME_LEN, + ANONYMOUS_UNION_INTERNAL_NAME) == 0) + || + (l.compare(l_pos1, + ANONYMOUS_ENUM_INTERNAL_NAME_LEN, + ANONYMOUS_ENUM_INTERNAL_NAME) == 0 + && r.compare(r_pos1, + ANONYMOUS_ENUM_INTERNAL_NAME_LEN, + ANONYMOUS_ENUM_INTERNAL_NAME) == 0)) + { + if (l_pos2 == l.npos || r_pos2 == r.npos) + return true; + + l_pos1 = l_pos2 + 2; + r_pos1 = r_pos2 + 2; + continue; + } + + if (l_pos2 == l.npos || r_pos2 == r.npos) + { + if (l_pos2 != r_pos2) + return false; + + return !l.compare(l_pos1, l_pos2, r, + r_pos1, r_pos2); + } + + if (l.compare(l_pos1, l_pos2 - l_pos1, r, + r_pos1, r_pos2 - r_pos1)) + return false; + + l_pos1 = l_pos2 + 2; + r_pos1 = r_pos2 + 2; + } + + return true; +} + /// If a given file is a symbolic link, get the canonicalized absolute /// path to the target file. /// diff --git a/tests/Makefile.am b/tests/Makefile.am index cae02a3b..544aa193 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -45,6 +45,7 @@ runtestaltdwarf \ runtestcorediff \ runtestabidiffexit \ runtestini \ +runtesttoolsutils \ $(CXX11_TESTS) if ENABLE_RUNNING_TESTS_WITH_PY3 @@ -133,6 +134,9 @@ runtesttypesstability_LDADD = libtestutils.la $(top_builddir)/src/libabigail.la runtestini_SOURCES = test-ini.cc runtestini_LDADD = libtestutils.la $(top_builddir)/src/libabigail.la +runtesttoolsutils_SOURCES = test-tools-utils.cc +runtesttoolsutils_LDADD = libtestutils.la $(top_builddir)/src/libabigail.la + runtestsvg_SOURCES=test-svg.cc runtestsvg_LDADD=$(top_builddir)/src/libabigail.la diff --git a/tests/data/test-diff-dwarf/test46-rust-report-0.txt b/tests/data/test-diff-dwarf/test46-rust-report-0.txt index c31efd42..87544b6f 100644 --- a/tests/data/test-diff-dwarf/test46-rust-report-0.txt +++ b/tests/data/test-diff-dwarf/test46-rust-report-0.txt @@ -10,6 +10,8 @@ Variables changes summary: 0 Removed, 0 Changed, 0 Added variable type size changed from 32 to 64 (in bits) 1 data member insertion: 'u32 two::Foo::b', at offset 32 (in bits) + 1 data member change: + name of 'one::Foo::a' changed to 'two::Foo::a' parameter 2 of type 'u32' was added diff --git a/tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt b/tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt index 725af787..75ba0a50 100644 --- a/tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt +++ b/tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-3.txt @@ -1,6 +1,6 @@ ================ changes of 'libspice-server.so.1.8.0'=============== -Leaf changes summary: 11 artifacts changed (8 filtered out) - Changed leaf types summary: 2 (8 filtered out) leaf types changed +Leaf changes summary: 11 artifacts changed (7 filtered out) + Changed leaf types summary: 2 (7 filtered out) leaf types changed Removed/Changed/Added functions summary: 1 Removed, 0 Changed, 8 Added functions Removed/Changed/Added variables summary: 0 Removed, 0 Changed, 0 Added variable diff --git a/tests/data/test-read-dwarf/PR22122-libftdc.so.abi b/tests/data/test-read-dwarf/PR22122-libftdc.so.abi index 40e0f1dd..2fde01b1 100644 --- a/tests/data/test-read-dwarf/PR22122-libftdc.so.abi +++ b/tests/data/test-read-dwarf/PR22122-libftdc.so.abi @@ -276,66 +276,66 @@ - + - + - - + + - - - + + + - + - - + + - - + + - - + + - + - + - + - - + + @@ -343,918 +343,918 @@ - + - + - - + + - + - + - - + + - + - + - + - + - - - + + + - + - + - + - - + + - - + + - - + + - + - + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - + + - - + + - + - - + + - - + + - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - + + + - - + + - - - + + + - - - + + + - - - - + + + + - - - + + + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - - - - - + + + + + + - - - - + + + + - + - - - + + + - + - - + + - - + + - - + + - - + + - - - - + + + + - - + + - + - + - - - + + + - - - + + + - + - + - + - + - - - + + + - - - + + + - - + + - + - - + + - - - - + + + + - - - + + + - - + + - - + + - + - - + + - + - - - + + + - + - - - - + + + + - + - - - - + + + + - - + + - + - - + + - + - + - - + + - + - + - + - + - - + + - - + + - - + + - - + + - + - + - - + + - - - + + + - + - - + + - - + + - - - - + + + + - - - - + + + + - + - - + + - + - + - - - + + + - - + + - - + + - + - - + + - - - + + + - - + + - - + + - + - + - - + + - - - + + + - - - + + + - - + + - + - + - - + + - + - - + + - - - + + + - - + + - - + + - + - + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - + - - - + + + - - + + - - - + + + - - + + - - + + - + - + - + - + - - - + + + - - - - + + + + - + - - + + @@ -1262,1831 +1262,1831 @@ - - - + + + - + - + - + - + - + - - - - + + + + - - - + + + - + - + - + - + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - - - - - - - - + + + + + + + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - - + + + - - + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - + - - + + - + - - + + - + - - - - - + + + + + - - - - + + + + - - - - - - - - + + + + + + + + - - + + - - + + - - - - - + + + + + - - - + + + - - + + - - - + + + - + - - + + - + - - - + + + - - + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - - + + + + + + + + - - - - - + + + + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - - - - + + + + + - - - + + + - - - + + + - - - + + + - + - - - + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - + - + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - + - - - + + + - - - - + + + + - + - - - - + + + + - - - + + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - - + + + + + + - - - + + + - - + + - - - + + + - + - + - - + + - - + + - - + + - - - + + + - - + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - + - - - + + + - + - - + + - - - + + + - - - - + + + + - - - - + + + + - - + + - - - - + + + + - - - + + + - + - - + + - - - + + + - - + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - + + - + - - + + - - + + - - + + - - + + - - - - - - - - - + + + + + + + + + - - - + + + - - - - + + + + - - - + + + - - + + - + - - - + + + - - - + + + - - - - - + + + + + - - - - + + + + - - + + - + - - - - + + + + - - + + - - - + + + - - + + - - - - - + + + + + - - + + - + - + - + - + - - - + + + - - + + - - + + - - + + - - - + + + - + - + - + - - + + - - - - - + + + + + - - + + - + - - + + - + - + - - + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - + + + - + - - - + + + - - - + + + - - - - - + + + + + - - - - + + + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - + - - - + + + - - - + + + - - + + - - + + - + - - - + + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - + + + + - - - + + + - - + + - - + + - - + + - - + + - + - - + + - - + + - - - + + + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - - - - - + + + + + + + - - + + - - - + + + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - - - + + + - + - + - + - - - + + + @@ -3102,33 +3102,33 @@ - + - - + + - - + + - - - + + + - + @@ -3137,306 +3137,306 @@ - + - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - - + + - - + + - - + + - - + + - + - + - + - + - - + + - + - - - + + + - - + + - - + + - + - - - + + + - + - - + + - + - - - + + + - + - + - + - + - - + + - + - + - + - + - - + + - + - + - - + + - + - + - + - + - + - + - + - + - - - - + + + + - - - + + + - - + + - + - - - - + + + + - + - - + + - + - - + + @@ -3444,313 +3444,313 @@ - - + + - - + + - - - + + + - + - + - + - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - + - - + + - - - - + + + + - + - - + + - + - - + + - + - + - + - + - + - - + + - + - - - + + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - + - - - + + + - - + + - - + + - - - + + + - - + + - + - - + + - - + + - - + + - - + + - - + + - + - - - + + + - + - - - + + + - + - - - + + + - - - + + + - + - - - + + + @@ -3758,228 +3758,228 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - + + + - + - - + + - - + + - - + + - - + + - - + + - + - + - + - - - + + + - - + + - - - - + + + + - - - - - + + + + + - - + + - + - - + + - - - + + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -4012,69 +4012,69 @@ - + - - + + - + - + - + - - - - - - - + + + + + + + - + - - + + - - + + - + - - + + - - + + - - - + + + @@ -4083,465 +4083,465 @@ - - - + + + - - - - + + + + - - + + - + - + - - + + - - - + + + - + - + - + - - + + - + - + - + - - + + - + - + - - + + - - + + - + - - - + + + - + - - - - + + + + - + - - + + - + - + - + - + - - + + - - + + - - - + + + - - - + + + - + - + - - + + - - - + + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - - + + - - + + - - - + + + - - + + - + - - + + - - + + - + - + - + - + - + - - + + - + - + - + - - - - + + + + - - + + - - - - + + + + - - - - + + + + - - - + + + - - + + - + - - + + - - + + - + - + - - + + - - + + - - - + + + - - + + - - + + - + - + - + - + - - - + + + - + - - - + + + - - - + + + - + + + + - - - - + - + - - + + - - - + + + - - - - + + + + - + - + - - + + @@ -4549,129 +4549,129 @@ - - + + - - + + - - + + - + - - - + + + - - + + - - - + + + - - + + - + - - + + - + - - - - + + + + - + - - + + + - - + - - + + - - + + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -4688,18 +4688,18 @@ - + - - + + - - - + + + @@ -4708,606 +4708,606 @@ - - + + - + - - + + - - + + - + - + - + - + - + - + - - - - - + + + + + - - + + - - + + - + - - + + - + - + - + - + - + - + - - + + - - - + + + - - + + - + - + - - + + - - + + - - - + + + - - + + - + - + - - + + - - - - + + + + - + - + - + - + - + - + - + - + - + - + - - + + - + - - - + + + - + - - - - - + + + + + - + - - + + - - + + - + - - - + + + - - + + - - - + + + - - + + - - - + + + - + - - - - + + + + - - + + - + - - + + - + - - + + - + - + - + - + - + - + - + - + - + - - - - + + + + - - - - + + + + - + - - + + - + - + - - + + - - + + - + - - - + + + - - + + - + - - + + - + - - + + - + - - - - + + + + - + - + - - - + + + - - + + - - - + + + - + - + - - + + - - - + + + - - + + - - + + - + - - + + - + - - - + + + - - + + - + - + - + - + - - - + + + - + - + - + - + - + - - + + - - + + - - + + - - - + + + - - - + + + - - - + + + - + - - + + - - + + @@ -5315,191 +5315,191 @@ - + - - + + - - - + + + - + - + - - + + - - + + - + - - + + - + - + - - - - - - + + + + + + - - + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - + - + - + - - - - + + + + - - + + - + - - - + + + - - - + + + - - - + + + - - + + @@ -5509,66 +5509,66 @@ - + - - - + + + - - - + + + - - - + + + - + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + @@ -5585,52 +5585,52 @@ - + - + - - - - - - + + + + + + - + - + - + - - + + - + - - - - - + + + + + @@ -5640,109 +5640,109 @@ - - + + - + - + - - + + - - + + - - + + - - + + - + - - + + - - - - - + + + + + - - + + - + - - + + - + - + - + - + - + @@ -5750,120 +5750,120 @@ - + - - + + - - - + + + - - + + - + - + - + - - + + - + + - - - - - + + + + - + - - - + + + - - - - - + + + + + - - - + + + - - + + - - + + - - - - + + + + - - - - + + + + - + - - + + @@ -5871,424 +5871,424 @@ - + - - - + + + - - + + - - + + - - + + - - - + + + - - - + + + - - + + - + - + - - - - - - + + + + + + - - - + + + - + - - - - - - + + + + + + - + - + - + - + - + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - + + + + + + - + - + - - - - - - + + + + + + - - - - - - + + + + + + - + - + - - - + + + - - - + + + - + - - + + - - - - - - + + + + + + - + - + - + - - - - - - + + + + + + - - - + + + - + - - - + + + - + - + - + - - + + - + - - + + - - + + - + + - - + - - - - + + + + - + - + - + - + - + - - + + - + - - + + - - + + - - - + + + - - - + + + - - + + - - - + + + - - - + + + - + - - - + + + - - + + - + - + - - + + - + - + - - + + - + - + - - + + @@ -6297,51 +6297,51 @@ - + - + - - + + - - + + - + - - + + - + - - - - + + + + - - + + - + @@ -6353,97 +6353,97 @@ - - - + + + - + - + - - + + - - + + - + - + - + - + - + - + - + - + - - + + - - - + + + - - + + - + @@ -6454,32 +6454,32 @@ - + - + - + - - + + - - + + - - + + @@ -6487,14 +6487,14 @@ - - - - + + + + - + @@ -6502,40 +6502,40 @@ - + - + - + - - - - + + + + - + - - + + - - + + - + - + @@ -6544,682 +6544,682 @@ - + - + - - - - + + + + - - - + + + - - - - - + + + + + - - - - - + + + + + - - - + + + - - + + - + - + - - + + - + - - + + - - - - + + + + - - + + - + - - + + - - + + - + - + - + - + - - - + + + - - + + - - + + - + - + - + - - + + - - + + - - + + - - + + - + - + - + - - - + + + - - + + - - + + - + - - - + + + - + - - - - + + + + - - + + - - + + - - - - + + + + - - + + - + - - - + + + - + - - - + + + - + - + - + - - + + - + - + - - + + - - - - + + + + - - + + - - + + - - - + + + - + - - - - - - + + + + + + - + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - - + + + + - - + + - - - - + + + + - + - + - - - - + + + + - + - - - - + + + + - + - - - - + + + + - + - + - - + + - - - + + + - - - + + + - - + + - + - + - - - + + + - + - + - + - + - - - + + + - + - - - + + + - + - + - - + + - + - - + + - + - + - - - - - - - - + + + + + + + + - - + + - - - + + + - + - - + + - - + + - + - - - - + + + + - - + + - + - - - - - + + + + + - - + + - - + + - - - - + + + + - - - - - + + + + + - - + + - - - + + + - - - - - + + + + + - - - - - + + + + + - - + + - + - - + + - - - + + + - + - + - - - + + + - - + + - - + + - - + + - + - - - - - - + + + + + + - + - - + + - - + + - + - + - - + + @@ -7227,63 +7227,63 @@ - - - + + + - + - - - + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - + - + - - + + @@ -7294,7 +7294,7 @@ - + @@ -7305,14 +7305,14 @@ - + - + - - + + @@ -7320,25 +7320,25 @@ - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + + @@ -7348,410 +7348,410 @@ - + - - - + + + - + - + - - + + - - - + + + - + - + - + - + - + - + - - + + - - + + - - + + - - - - - + + + + + - - - + + + - - - - + + + + - - + + - - - - - + + + + + - - + + - - + + - - - - + + + + - + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - + - - - - + + + + - + - - - - + + + + - + - - + + - - - + + + - - - + + + - + + + - - - + - + - - - - + + + + - + - + - + - - - + + + - - + + - + - + - - + + - + - + - + - + - - - - - - + + + + + + - + - - + + - - + + - - + + - - - + + + - + - + - + - - + + - - + + - - + + - - - - - - - - + + + + + + + + - + - + - + - + - - + + - - - - + + + + - - - + + + - - - - + + + + - + - - - + + + - - - + + + - - - + + + - - - - - - - + + + + + + + - - + + - + - - + + - + - - + + - + @@ -7768,70 +7768,70 @@ - + - + - + - + - + - - - - - + + + + + - + - + - + - - + + - - + + - - - - - + + + + + @@ -7839,203 +7839,203 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - + - - + + - + - + - - + + - + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - + - - - + + + - + - - - - - - + + + + + + - - + + - - + + - - + + - - - + + + - + - + - - + + - - + + - + - - + + - + - - + + - + - + - + - - - + + + - - + + - + - + - - + + - - + + - - - + + + @@ -8054,20 +8054,20 @@ - - - - - - - + + + + + + + - - - - - - + + + + + + @@ -8076,853 +8076,853 @@ - + - + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - + - - - + + + - - - + + + - - - + + + - - - - - + + + + + - + - - - - - - + + + + + + - - + + - - - + + + - - - + + + - + - - - - - - - - - + + + + + + + + + - - - - + + + + - - - + + + - - - + + + - - - + + + - - + + - - + + - - + + - - - + + + - - - - - - - - + + + + + + + + - - + + - - + + - - - + + + - - + + - - + + - + - + - - + + - - + + - + - + - + - + - - - + + + - - - + + + - + - + - - - + + + - + - + - - - + + + - + - + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - + - - - - + + + + - - - + + + - - - - + + + + - - - + + + - - - - + + + + - - - + + + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - - + + - - + + - - + + - - + + - - - + + + - - + + - - + + - + - - - + + + - + - + - - + + - - + + - - + + - - + + - - + + - - - + + + - - - - + + + + - - - - + + + + - - - - - + + + + + - - - - - - + + + + + + - - - - + + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + + - - + + - + - - - - + + + + - + - - + + - + - - - + + + - - - + + + - - + + - - - - + + + + - + - - + + - + - - + + - - + + - - + + - - + + - - + + - + - + - + - - - + + + - - - + + + - - - + + + - - - + + + - - + + - + - - - + + + - - - + + + - - - + + + - - - - - - - + + + + + + + - + - - + + - + - - + + - + - + + + + - - - - + - + - - + + diff --git a/tests/test-tools-utils.cc b/tests/test-tools-utils.cc new file mode 100644 index 00000000..da6f44de --- /dev/null +++ b/tests/test-tools-utils.cc @@ -0,0 +1,90 @@ +// -*- Mode: C++ -*- +// +// Copyright (C) 2013-2019 Red Hat, Inc. +// +// This file is part of the GNU Application Binary Interface Generic +// Analysis and Instrumentation Library (libabigail). This library is +// free software; you can redistribute it and/or modify it under the +// terms of the GNU Lesser General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) any +// later version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. + +// You should have received a copy of the GNU Lesser General Public +// License along with this program; see the file COPYING-LGPLV3. If +// not, see . + +/// @file +/// +/// This is a collection of unit tests for functions defined in +/// abg-tgools-utils.cc. + +#include +#include "abg-tools-utils.h" + +using namespace abigail::tools_utils; +using std::cerr; + +int +main(int, char**) +{ + + /// These are unit tests for abigail::tools_utils::decl_names_equal. + /// Just run the resulting runtesttoolsutils program under the + /// debugger to debug this if need be. + + ABG_ASSERT(decl_names_equal("foo", "foo") == true); + + ABG_ASSERT(decl_names_equal("foo", "bar") == false); + + ABG_ASSERT(decl_names_equal("__anonymous_struct__1::foo", + "__anonymous_struct__2::foo") == true); + + ABG_ASSERT(decl_names_equal + ("__anonymous_struct__1::foo::__anonymous_struct__2::bar", + "__anonymous_struct__10::foo::__anonymous_struct__11::bar") + == true); + + ABG_ASSERT(decl_names_equal + ("__anonymous_union__1::foo::__anonymous_union__2::bar", + "__anonymous_union__10::foo::__anonymous_union__11::bar") + == true); + + ABG_ASSERT(decl_names_equal + ("__anonymous_enum__1::foo::__anonymous_enum__2::bar", + "__anonymous_enum__10::foo::__anonymous_enum__11::bar") + == true); + + ABG_ASSERT(decl_names_equal + ("__anonymous_struct__1::bar::__anonymous_struct__2::baz", + "__anonymous_struct__10::foo::__anonymous_struct__11::bar") + == false); + + ABG_ASSERT(decl_names_equal + ("__anonymous_struct__1::foo::__anonymous_struct__2::baz", + "__anonymous_struct__10::foo::__anonymous_struct__11::bar") + == false); + + ABG_ASSERT(decl_names_equal + ("__anonymous_struct__1::foo::__anonymous_struct__2::bar", + "__anonymous_struct__10::foo::__anonymous_union__11::bar") + == false); + + ABG_ASSERT(decl_names_equal + ("__anonymous_struct__1::foo::__anonymous_struct__2::bar", + "__anonymous_struct__10::foo::__anonymous_enum__11::bar") + == false); + + ABG_ASSERT(decl_names_equal + ("OT::Extension::__anonymous_union__", + "OT::Extension::__anonymous_union__") + == true); + + ABG_ASSERT(decl_names_equal("S0::m2", "S0::m12") == false); + + return 0; +}