Bug 26135 - Wrong linkage name causes anonymous classes miscomparison

When comparing decls, the overload of the 'equals' function for
instances of decl_base compares their linkage names.  If they are
different, then the decls are generally considered different.

Class declarations (and definitions) also use the 'equals' function
referred to above.  So when two classes have different linkage names,
they are always considered different.

Now let's consider the case of an anonymous class.  It doesn't have
any user-provided name, by definition.  Libabigail does, however,
assigns it an internal name for various (internal) purposes.  That
internal name is generally ignored for the purpose of (anonymous) type
comparison.  So by design, two anonymous classes can have different
internal anonymous names and yet still happen to be equal.

The root issue in this problem report is that by default, the linkage
name of a class is set to its name.  And when that class is anonymous,
its internal name is used as its linkage name.  Oops.  That leads to
anonymous classes being wrongly considered different.

This patch fixes the issue by providing additional constructors for a
class type to avoid using the internal anonymous name as its linkage
name.

Note that the same issue is present for unions so the patch does the
a similar thing for union types.

Enums are properly handled so we don't need to do anything in that
regard.

For good measure, the patch also adds an assert to
type_base::get_canonical_types_for to ensure that anonymous class or
union types don't have linkage names for now.

	* include/abg-ir.h (class_decl::class_decl): Add two overloads
	that take the "is_anonymous" flag.
	(union_decl::union_decl): Likewise.
	* src/abg-ir.cc (class_decl::class_decl): Define two overloads
	that take the "is_anonymous" flag and set the linkage name
	accordingly.
	(union_decl::union_decl): Likewise.
	(type_base::get_canonical_type_for): Assert that an anonymous
	class or union can't have a linkage name for now.
	* src/abg-dwarf-reader.cc (add_or_update_class_type)
	(add_or_update_union_type): Use a new overload for the constuctor
	of {class, union}_decl and set the "is_anonymous" flag.  Don't use
	decl_base::set_is_anonymous anymore.
	* src/abg-reader.cc (build_class_decl, build_union_decl):
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Adjust.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
7 files changed