public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, applied] Bug 28316 - Failure to represent typedef named anonymous enums
@ 2021-09-21 15:20 Dodji Seketeli
  0 siblings, 0 replies; only message in thread
From: Dodji Seketeli @ 2021-09-21 15:20 UTC (permalink / raw)
  To: libabigail

[-- Attachment #1: Type: text/plain, Size: 10437 bytes --]

Hello,

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>
Applied to master.
---
 include/abg-fwd.h                             |     6 +
 include/abg-ir.h                              |    15 +-
 src/abg-dwarf-reader.cc                       |    17 +-
 src/abg-ir.cc                                 |   193 +-
 src/abg-reader.cc                             |    63 +-
 src/abg-writer.cc                             |    11 +-
 tests/data/Makefile.am                        |     5 +
 .../test-abidiff-exit/test-PR28316-report.txt |    12 +
 .../data/test-abidiff-exit/test-PR28316-v0.cc |    10 +
 .../data/test-abidiff-exit/test-PR28316-v0.o  |   Bin 0 -> 3024 bytes
 .../data/test-abidiff-exit/test-PR28316-v1.cc |    11 +
 .../data/test-abidiff-exit/test-PR28316-v1.o  |   Bin 0 -> 3032 bytes
 tests/data/test-annotate/libtest23.so.abi     |    18 +-
 .../test-annotate/libtest24-drop-fns-2.so.abi |    10 +-
 .../test-annotate/libtest24-drop-fns.so.abi   |    10 +-
 .../data/test-annotate/test13-pr18894.so.abi  |   668 +-
 .../data/test-annotate/test14-pr18893.so.abi  |    36 +-
 .../data/test-annotate/test15-pr18892.so.abi  |    70 +-
 .../data/test-annotate/test21-pr19092.so.abi  |  2414 +-
 .../test-diff-dwarf/test15-enum-report.txt    |     8 +-
 .../test-diff-filter/test19-enum-report-1.txt |     8 +-
 .../test30-pr18904-rvalueref-report0.txt      |   234 +-
 .../test30-pr18904-rvalueref-report1.txt      |   234 +-
 .../test30-pr18904-rvalueref-report2.txt      |   234 +-
 .../test35-pr18754-no-added-syms-report-0.txt |   234 +-
 .../PR24690/PR24690-report-0.txt              |     6 +-
 .../nss-3.23.0-1.0.fc23.x86_64-report-0.txt   |    36 +-
 ...l7.x86_64-0.12.8-1.el7.x86_64-report-0.txt |    22 +-
 ...l7.x86_64-0.12.8-1.el7.x86_64-report-1.txt |    20 +-
 ...l7.x86_64-0.12.8-1.el7.x86_64-report-2.txt |    40 +-
 ...l7.x86_64-0.12.8-1.el7.x86_64-report-3.txt |    18 +-
 .../PR22015-libboost_iostreams.so.abi         |  2022 +-
 .../test-read-dwarf/PR22122-libftdc.so.abi    |  4299 +--
 .../data/test-read-dwarf/PR25007-sdhci.ko.abi |   110 +-
 .../PR25042-libgdbm-clang-dwarf5.so.6.0.0.abi |    16 +-
 tests/data/test-read-dwarf/libtest23.so.abi   |     4 +-
 .../libtest24-drop-fns-2.so.abi               |     2 +-
 .../test-read-dwarf/libtest24-drop-fns.so.abi |     2 +-
 .../test-read-dwarf/test-libaaudio.so.abi     |    18 +-
 .../test-read-dwarf/test-libandroid.so.abi    |   161 +-
 .../test-read-dwarf/test10-pr18818-gcc.so.abi |   242 +-
 .../test-read-dwarf/test11-pr18828.so.abi     |    12 +-
 .../test-read-dwarf/test12-pr18844.so.abi     | 19414 ++++++-----
 .../test-read-dwarf/test13-pr18894.so.abi     |   600 +-
 .../test-read-dwarf/test14-pr18893.so.abi     |     8 +-
 .../test-read-dwarf/test15-pr18892.so.abi     |    20 +-
 .../test-read-dwarf/test16-pr18904.so.abi     |  3425 +-
 .../test-read-dwarf/test21-pr19092.so.abi     |  2281 +-
 .../test22-pr19097-libstdc++.so.6.0.17.so.abi | 26475 ++++++++--------
 .../test9-pr18818-clang.so.abi                |  2305 +-
 tests/test-abidiff-exit.cc                    |    11 +
 51 files changed, 33328 insertions(+), 32762 deletions(-)

The patch is big so I am attaching it, gzipped.


[-- Attachment #2: 0002-Bug-28316-Failure-to-represent-typedef-named-anonymo.patch.gz --]
[-- Type: application/gzip, Size: 684892 bytes --]

[-- Attachment #3: Type: text/plain, Size: 13 bytes --]


-- 
		Dodji

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-21 15:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21 15:20 [PATCH, applied] Bug 28316 - Failure to represent typedef named anonymous enums Dodji Seketeli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).