libabigail/include
Dodji Seketeli 321da66678 Bug 28316 - Failure to represent typedef named anonymous enums
Consider these two anonymous enum declarations in these different contexts:

enum {A0 = 0; A1 = 1;} global0; // 1/: anonymous enum

typedef enum {E0 = 0; E1 = 1;} E; // 2/: anonymous enum named by a typedef.
E global0;

In the first context "1/", the type of the global variable is an
anonymous enum that is used as such.

In the second context "2/", the type of the global variable is an
anonymous type that is named by the typedef 'E'.  So then, it's E that
is used to designate the enum.  The anonymous type is thus never used
directly.  In essence, it's the same thing as if it was declared as
enum E {E0 = 0; E1 = 1;};

Right now, libabigail canonicalizes the enum 1/ and 2/ together and
that results in 1/ being canonically equal to 2/.

So, when saving the corpus into abixml, because enum 1/ and enum 2/ can be
used interchangeably, either 1/ or 2/ is going to be saved.  That
can result in spurious change reports in which the reporter refer to
the enum 1/ where it should refer to enum 2/ or vice versa.

Intrinsically, the enum 1/ and enum 2/ are different because one
essentially has a name (provided by a typedef) and the second does
not.  One is anonymous whereas the second is not, essentially.

At the moment, libabigail supports typedef-named anonymous classes.
But it doesn't support this concept for enums.

This patch extends that concept to enums as well.  It makes it so that
any anonymous type can now by typedef-named.  In that case, the type
now looks like it has a name which is the typedef name.  The
information about the typedef naming a given type is kept and
serialized into abixml.

Thus with this patch, the enum in 1/ is now considered (canonically)
different from enum 2/.  So there is no possible confusion once the
type is serialized into abixml.

	* include/abg-fwd.h (scope_anonymous_or_typedef_named)
	(is_anonymous_or_typedef_named): Declare new functions.
	* include/abg-ir.h (decl_base::set_has_anonymous_parent): Remove
	declaration.
	(decl_base::{get,set}_naming_typedef): Declare new member
	functions.
	* src/abg-ir.cc (update_qualified_name): Define static function.
	(decl_base::priv::naming_typedef_): Define new data member.
	(decl_base::priv::has_anonymous_parent_): Remove data member.
	(decl_base::priv::priv): Adjust constructor.
	(decl_base::get_has_anonymous_parent): Rather than storing a flag
	for this, dynamically look at if the scope is anonymous.
	(decl_base::set_has_anonymous_parent): Remove definition.
	(decl_base::{get,set}_naming_typedef): Define new member
	functions.
	(scope_anonymous_or_typedef_named)
	(is_anonymous_or_typedef_named): Define new functions.
	(get_decl_name_for_comparison): Define new sub-routine for the
	decl_base overload of equals.
	(equals): In the overload for decl_base, use the new
	get_decl_name_for_comparison.  It helps to ensure that all
	anonymous decls of the same kind have the same name for the
	purpose of comparison.  It also ensures that non anonymous decls
	that are part of anonymous scopes should be compared only by
	looking at their non-qualified names.  In the overload for
	class_or_union, adjust.
	(scope_decl::add_member_decl): No more need to flag the fast that
	the parent scope is anonymous here.
	(get_debug_representation): Fix a thinko.
	(class_or_union::get_naming_typedef): Remove member function as
	it's now handled by decl_base::get_naming_typedef.
	* src/abg-dwarf-reader.cc (build_typedef_type): When a typedef is
	a naming typedef, then mark the named decl as being typedef-named.
	(maybe_canonicalize_type): Delay canonicalization of anonymous
	types because they can be typedef-named later.
	* src/abg-reader.cc (read_naming_typedef_id_string)
	(maybe_set_naming_typedef): Define new static function.
	(build_class_decl): Use it here, rather than reading the
	"naming-typedef-id" by hand.
	(build_enum_type_decl, build_union_decl): Read the
	"naming-typedef-id" property.
	* src/abg-writer.cc (write_naming_typedef): Make this accept
	decl_base_sptr, rather than just class_decl_sptr.
	(write_enum_type_decl): Write the naming-typedef-id property if
	needed.
	* tests/data/test-abidiff-exit/test-PR28316-report.txt: New test
	reference output.
	* tests/data/test-abidiff-exit/test-PR28316-v{0,1}.cc: Source code
	of new binary test input.
	* tests/data/test-abidiff-exit/test-PR28316-v{0,1}.o: New binary
	test input files.
	* tests/data/Makefile.am: Add the new test files to the source
	distribution.
	* tests/test-abidiff-exit.cc: Add the new test files above to this
	harness.
	* tests/data/test-annotate/libtest23.so.abi: Adjust.
	* tests/data/test-annotate/libtest24-drop-fns-2.so.abi: Likewise.
	* tests/data/test-annotate/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-annotate/test13-pr18894.so.abi: Likewise.
	* tests/data/test-annotate/test14-pr18893.so.abi: Likewise.
	* tests/data/test-annotate/test15-pr18892.so.abi: Likewise.
	* tests/data/test-annotate/test21-pr19092.so.abi: Likewise.
	* tests/data/test-diff-dwarf/test15-enum-report.txt: Likewise.
	* tests/data/test-diff-filter/test19-enum-report-1.txt: Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report0.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report1.txt:
	Likewise.
	* tests/data/test-diff-filter/test30-pr18904-rvalueref-report2.txt:
	Likewise.
	* tests/data/test-diff-filter/test35-pr18754-no-added-syms-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/PR24690/PR24690-report-0.txt: Likewise.
	* tests/data/test-diff-pkg/nss-3.23.0-1.0.fc23.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-0.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-1.txt:
	Likewise.
	* tests/data/test-diff-pkg/spice-server-0.12.4-19.el7.x86_64-0.12.8-1.el7.x86_64-report-2.txt:
	Likewise.
	* 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/PR22015-libboost_iostreams.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/PR22122-libftdc.so.abi: Likewise.
	* tests/data/test-read-dwarf/PR25007-sdhci.ko.abi: Likewise.
	* tests/data/test-read-dwarf/PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest23.so.abi: Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns-2.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/libtest24-drop-fns.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libaaudio.so.abi: Likewise.
	* tests/data/test-read-dwarf/test-libandroid.so.abi: Likewise.
	* tests/data/test-read-dwarf/test10-pr18818-gcc.so.abi: Likewise.
	* tests/data/test-read-dwarf/test11-pr18828.so.abi: Likewise.
	* tests/data/test-read-dwarf/test12-pr18844.so.abi: Likewise.
	* tests/data/test-read-dwarf/test13-pr18894.so.abi: Likewise.
	* tests/data/test-read-dwarf/test14-pr18893.so.abi: Likewise.
	* tests/data/test-read-dwarf/test15-pr18892.so.abi: Likewise.
	* tests/data/test-read-dwarf/test16-pr18904.so.abi: Likewise.
	* tests/data/test-read-dwarf/test21-pr19092.so.abi: Likewise.
	* tests/data/test-read-dwarf/test22-pr19097-libstdc++.so.6.0.17.so.abi:
	Likewise.
	* tests/data/test-read-dwarf/test9-pr18818-clang.so.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2021-09-21 16:37:44 +02:00
..
abg-comp-filter.h Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-comparison.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-config.h Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-corpus.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-cxx-compat.h abg-cxx-compat: add simplified version of std::optional 2021-03-09 10:41:10 +01:00
abg-diff-utils.h Drop unneccessary includes of abg-cxx-compat.h 2020-12-15 09:23:44 +01:00
abg-dwarf-reader.h dwarf reader: drop (now) unused code related to symbol table reading 2021-04-02 15:48:23 +02:00
abg-fwd.h Bug 28316 - Failure to represent typedef named anonymous enums 2021-09-21 16:37:44 +02:00
abg-hash.h Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-ini.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-interned-str.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-ir.h Bug 28316 - Failure to represent typedef named anonymous enums 2021-09-21 16:37:44 +02:00
abg-libxml-utils.h reader: Use xmlFirstElementChild and xmlNextElementSibling rather than xml::advance_to_next_sibling_element 2021-05-03 17:15:22 +02:00
abg-reader.h Detect abixml canonical type instability during abidw --debug-abidiff 2021-05-25 12:24:26 +02:00
abg-regex.h Drop unneccessary includes of abg-cxx-compat.h 2020-12-15 09:23:44 +01:00
abg-reporter.h Drop unneccessary includes of abg-cxx-compat.h 2020-12-15 09:23:44 +01:00
abg-sptr-utils.h Drop unneccessary includes of abg-cxx-compat.h 2020-12-15 09:23:44 +01:00
abg-suppression.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-tools-utils.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-traverse.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-version.h.in Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-viz-common.h Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-viz-dot.h Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-viz-svg.h Re-license the project to Apache v2 With LLVM Exception 2020-12-02 11:49:13 +01:00
abg-workers.h Consistently use std::unique_ptr for private implementations (pimpl) 2021-07-16 11:16:47 +02:00
abg-writer.h Bug 27236 - Don't forget to emit some referenced types 2021-08-11 17:39:49 +02:00
Makefile.am Bug 27512 - Remove broken zip-archive support 2021-03-19 10:52:57 +01:00