comparison: Sort anonymous types using their flat representation

Message ID 87wmjuiic9.fsf@redhat.com
State New
Headers
Series comparison: Sort anonymous types using their flat representation |

Commit Message

Dodji Seketeli Sept. 2, 2024, 8:13 a.m. UTC
  Hello,

When changes to types non-reachable from external interfaces are
emitted, they are sorted using the pretty representation of said
types.  In the current form, it's the "internal" pretty representation
that is used for the sorting.  That internal form, which is normally
used for the purpose of type canonicalization, doesn't differentiate
an anonymous types against another one.  For instance, all anonymous
enums are named __anonymous_enum__.  In that case, the sorting of
anonymous type changes becomes non stable.

This patch uses the non-internal form of type pretty representation
for the sorting.  In that form, anonymous enums are named using their
flat representation.

	* src/abg-comparison-priv.h (diff_comp::operator()): Use the
	non-internal pretty representation for sorting.
	* tests/data/test-abidiff-exit/test-anon-types-report-1.txt:
	Adjust.
	* tests/data/test-abidiff-exit/test-anonymous-enums-change-report-v1.txt:
	Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 src/abg-comparison-priv.h                              |  4 ++--
 .../test-abidiff-exit/test-anon-types-report-1.txt     | 10 +++++-----
 .../test-anonymous-enums-change-report-v1.txt          | 10 +++++-----
 3 files changed, 12 insertions(+), 12 deletions(-)
  

Patch

diff --git a/src/abg-comparison-priv.h b/src/abg-comparison-priv.h
index 5f63cf64..0e3569d5 100644
--- a/src/abg-comparison-priv.h
+++ b/src/abg-comparison-priv.h
@@ -881,9 +881,9 @@  struct diff_comp
   bool
   operator()(const diff& l, diff& r) const
   {
-    return (get_pretty_representation(l.first_subject(), true)
+    return (get_pretty_representation(l.first_subject())
 	    <
-	    get_pretty_representation(r.first_subject(), true));
+	    get_pretty_representation(r.first_subject()));
   }
 
   /// Lexicographically compare two diff nodes.
diff --git a/tests/data/test-abidiff-exit/test-anon-types-report-1.txt b/tests/data/test-abidiff-exit/test-anon-types-report-1.txt
index 916b880d..2ff8167c 100644
--- a/tests/data/test-abidiff-exit/test-anon-types-report-1.txt
+++ b/tests/data/test-abidiff-exit/test-anon-types-report-1.txt
@@ -9,17 +9,17 @@  Unreachable types summary: 2 removed, 3 changed, 0 added types
 
 3 changed types unreachable from any public interface:
 
-  [C] 'struct {int a; int b;}' changed:
-    type size changed from 64 to 96 (in bits)
-    1 data member insertion:
-      'int c', at offset 64 (in bits) at test-anon-types-v1.c:18:1
-
   [C] 'enum {a=0, b=1, c=2, d=3, }' changed:
     type size hasn't changed
     2 enumerator insertions:
       'e' value '4'
       'f' value '5'
 
+  [C] 'struct {int a; int b;}' changed:
+    type size changed from 64 to 96 (in bits)
+    1 data member insertion:
+      'int c', at offset 64 (in bits) at test-anon-types-v1.c:18:1
+
   [C] 'union {int a; int b; int d;}' changed:
     type size hasn't changed
     1 data member change:
diff --git a/tests/data/test-abidiff-exit/test-anonymous-enums-change-report-v1.txt b/tests/data/test-abidiff-exit/test-anonymous-enums-change-report-v1.txt
index 8639fa44..0567e865 100644
--- a/tests/data/test-abidiff-exit/test-anonymous-enums-change-report-v1.txt
+++ b/tests/data/test-abidiff-exit/test-anonymous-enums-change-report-v1.txt
@@ -4,17 +4,17 @@  Unreachable types summary: 0 removed, 2 changed, 1 added types
 
 2 changed types unreachable from any public interface:
 
+  [C] 'enum {E3_0=0, E3_1=1, }' changed:
+    type size hasn't changed
+    1 enumerator insertion:
+      'E3_2' value '2'
+
   [C] 'enum {E4_0=0, E4_1=1, E4_2=2, E4_LAST_ELEMENT=3, }' changed:
     type size hasn't changed
     2 enumerator deletions:
       'E4_2' value '2'
       'E4_LAST_ELEMENT' value '3'
 
-  [C] 'enum {E3_0=0, E3_1=1, }' changed:
-    type size hasn't changed
-    1 enumerator insertion:
-      'E3_2' value '2'
-
 1 added type unreachable from any public interface:
 
   [A] 'enum {E5_0=0, E5_1=1, }' at test-anonymous-enums-change-v1.c:26:1