public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: "gprocida at google dot com" <sourceware-bugzilla@sourceware.org>
To: libabigail@sourceware.org
Subject: [Bug default/28939] New: diff output is sensitive to implementation of std::sort
Date: Thu, 03 Mar 2022 14:29:02 +0000	[thread overview]
Message-ID: <bug-28939-9487@http.sourceware.org/bugzilla/> (raw)

https://sourceware.org/bugzilla/show_bug.cgi?id=28939

            Bug ID: 28939
           Summary: diff output is sensitive to implementation of
                    std::sort
           Product: libabigail
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: default
          Assignee: dodji at redhat dot com
          Reporter: gprocida at google dot com
                CC: libabigail at sourceware dot org
  Target Milestone: ---

I received a notification that at least one abidiff is sensitive to the
particular implementation of std::sort.

std::sort gives no guarantees as to the relative ordering of elements that
compare equal (!(a < b) && !(b < a)).

The comparison functor diff_less_than_functor only examines the first diff
subjects and in general there is no guarantee that sorting distinct diffs will
yield a consistent ordering.

The particular test case that was reported was this one:

--- tests/data/test-abidiff-exit/test-member-size-report0.txt   2022-01-30
18:02:19.412941913 -0800
+++ tests/output/test-abidiff-exit/test-member-size-report0.txt 2022-01-30
18:02:20.180941537 -0800
@@ -4,16 +4,15 @@
 2 functions with some indirect sub-type change:

   [C] 'function void reg1(S*, T*, T*)' at test-member-size-v1.cc:26:1 has some
indirect sub-type changes:
-    parameter 1 of type 'S*' has sub-type changes:
-      in pointed to type 'struct S' at test-member-size-v1.cc:3:1:
-        type size changed from 128 to 192 (in bits)
-        1 data member insertion:
-          'int y', at offset 128 (in bits) at test-member-size-v1.cc:6:1
-        no data member change (1 filtered);
-    parameter 2 of type 'T*' has sub-type changes:
+    parameter 3 of type 'T*' has sub-type changes:
       in pointed to type 'struct T' at test-member-size-v1.cc:14:1:
         type size changed from 192 to 256 (in bits)
-        1 data member changes (1 filtered):
+        2 data member changes:
+          type of 'S s' changed:
+            type size changed from 128 to 192 (in bits)
+            1 data member insertion:
+              'int y', at offset 128 (in bits) at test-member-size-v1.cc:6:1
+            no data member change (1 filtered);
           'int a' offset changed from 128 to 192 (in bits) (by +64 bits)


In general, dependence on the implementation of std::sort can be discovered by
randomising the input order before sorting.

There are two approaches to improving order stability:

1. increase the discrimination of the comparison function
2. use stable_sort

I'll try to post a patch that does both.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

             reply	other threads:[~2022-03-03 14:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-03 14:29 gprocida at google dot com [this message]
2022-03-03 14:57 ` [Bug default/28939] " gprocida at google dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-28939-9487@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).