PR30048 - wrong pretty representation of qualified pointers
authorDodji Seketeli <dodji@redhat.com>
Fri, 3 Feb 2023 00:15:41 +0000 (01:15 +0100)
committerDodji Seketeli <dodji@redhat.com>
Fri, 10 Feb 2023 12:15:27 +0000 (13:15 +0100)
commit03d8b52fc7a510edaf3182a3600cc54c0a180fe7
tree104e6db6f48be07e6e0c8d2a2b99b62c82250397
parent82973c898a8a5e1f3109f7f37dd5c3a89b431b51
PR30048 - wrong pretty representation of qualified pointers

A qualified type is textually represented as the following:

    <qualifier> <underlying-type>

were "qualifier" is the qualifier carried by the qualified type and
"underlying-type" is the type being qualified.

In this case, the qualifier prefixes the textual representation of the
qualified type.

This is true if the underlying type of the qualified type is a
non-const, non-reference type.  For instance:

    const int;

But when the underlying type is a pointer, then the qualified type is
represented as:

    int* const;

In that later case, the qualifier comes /after/ the textual
representation of the underlying type.

Now suppose the underlying type is itself a qualified type.  In that
case, for a non-const underlying type, we'd have, e.g:

    const volatile int;

where the qualifier precedes the qualified type (which is itself a
qualified type) /IF/ the ultimate underlying type (a.k.a the leaf
underlying type) is itself a non-const, non-reference type.

But if the ultimate underlying type is a pointer, a qualified type
with an underlying qualified type would be textually represented as,
e.g:

    int* const volatile;

In other words, if the leaf type is a pointer, the qualifier suffixes
the textual representation the underlying qualified type.

Libabigail is failing to apply this later rule.

As the type name is used as a key to cache IR nodes of DIEs (among
other things), getting it wrong can lead to a bumpy ride down the
road.

Fixed thus.

* src/abg-dwarf-reader.cc
(die_is_pointer_array_or_reference_type): Rename
die_is_pointer_or_reference_type into this.  This new name
reflects more what the function does as it tests if a DIE is for
pointer, an array or a reference.
(pointer_or_qual_die_of_anonymous_class_type): Adjust to use the
newly (and better) named die_is_pointer_array_or_reference_type.
(die_is_pointer_or_reference_type): Make this really test if a DIE
is for a pointer or a reference.  Now the name matches what the
function does.
(die_peel_qualified): Define new function.
(die_qualified_type_name): When a qualified name Q has another
qualified name as its underlying type, it's important to know if
the leaf type is a pointer type or not to know how to construct
the name of Q.  This change now peels the potential qualifiers
from the underlying type of the qualified type to see if the leaf
type is a pointer or not.
* src/abg-ir.cc (get_name_of_qualified_type): Likewise.  Also, the
name of array types doesn't follow the same rule as for pointers
and references.
* tests/data/test-abidiff-exit/PR30048-test-report-0.txt: Add new
reference test output.
* tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt:
Likewise.
* tests/data/test-abidiff-exit/PR30048-test-v{0,1}.c: Add source
code of binary input data.
* tests/data/test-abidiff-exit/PR30048-test-2-v{0,1}.cc: Likewise.
* tests/data/test-abidiff-exit/PR30048-test-v{0,1}.o: Add binary
input data.
* tests/data/test-abidiff-exit/PR30048-test-2-v{0,1}.o: Likewise.
* tests/data/Makefile.am: Add the new test material above to
source distribution.
* tests/test-abidiff-exit.cc (in_out_specs): Add the input
binaries to this test harness.
* tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt:
Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
15 files changed:
src/abg-dwarf-reader.cc
src/abg-ir.cc
tests/data/Makefile.am
tests/data/test-abidiff-exit/PR30048-test-2-report-1.txt [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-2-v0.cc [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-2-v0.o [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-2-v1.cc [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-2-v1.o [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-report-0.txt [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-v0.c [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-v0.o [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-v1.c [new file with mode: 0644]
tests/data/test-abidiff-exit/PR30048-test-v1.o [new file with mode: 0644]
tests/data/test-abidiff-exit/qualifier-typedef-array-report-1.txt
tests/test-abidiff-exit.cc