This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 1/5] Fix asymmetric comparison functions
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Yury Gribov <y dot gribov at samsung dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Andrey Belevantsev <abel at ispras dot ru>, Andrew MacLeod <amacleod at redhat dot com>, Andrew Pinski <pinskia at gmail dot com>, Diego Novillo <dnovillo at google dot com>, Geoff Keating <geoffk at geoffk dot org>, Jason Merrill <jason at redhat dot com>, Richard Biener <rguenther at suse dot de>, Steven Bosscher <steven at gcc dot gnu dot org>
- Date: Fri, 18 Dec 2015 21:07:00 +0100
- Subject: Re: [PATCH 1/5] Fix asymmetric comparison functions
- Authentication-results: sourceware.org; auth=none
- References: <5672787D dot 6040105 at samsung dot com> <56727936 dot 4030605 at samsung dot com> <20151217113903 dot GS18720 at tucnak dot redhat dot com> <5672A4D0 dot 8090509 at samsung dot com> <56746138 dot 9070709 at samsung dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Dec 18, 2015 at 10:40:40PM +0300, Yury Gribov wrote:
> So it seems most people generally agree that self-comparisons (cmp(x,x) ==
> 0) are useless and don't need to be checked or fixed. What about ensuring
> symmetry i.e. that cmp(x, y) == -cmp(y, x) forall x, y? One of the bugs
> (pair_cmp in fortran/interface.c) is exactly about this.
Ensuring symmetry for x != y is of course very much desirable.
So, if you could change your qsort interposer so that it for each comparison
x != y calls both cmp (x, y) and cmp (y, x) and asserts that
int r = cmp (x, y);
int ir = cmp (y, x);
if (r > 0) assert (ir < 0);
else if (r < 0) assert (ir > 0);
else assert (ir == 0);
it would be greatly appreciated. Note, the standard only talks about < 0, 0
and > 0, so it is fine if cmp (x, y) returns 231 and cmp (y, x) returns -142.
Jakub