public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Yury Gribov <y.gribov@samsung.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Andrey Belevantsev <abel@ispras.ru>,
	       Andrew MacLeod <amacleod@redhat.com>,
	       Andrew Pinski <pinskia@gmail.com>,
	Diego Novillo <dnovillo@google.com>,
	       Geoff Keating <geoffk@geoffk.org>,
	Jason Merrill <jason@redhat.com>,
	       Richard Biener <rguenther@suse.de>,
	       Steven Bosscher <steven@gcc.gnu.org>
Subject: Re: [PATCH 1/5] Fix asymmetric comparison functions
Date: Thu, 17 Dec 2015 11:39:00 -0000	[thread overview]
Message-ID: <20151217113903.GS18720@tucnak.redhat.com> (raw)
In-Reply-To: <56727936.4030605@samsung.com>

On Thu, Dec 17, 2015 at 11:58:30AM +0300, Yury Gribov wrote:
> 2015-12-17  Yury Gribov  <tetra2005@gmail.com>
> 
> 	* c-family/c-common.c (resort_field_decl_cmp):
> 	Make symmteric.
> 	* cp/class.c (method_name_cmp): Ditto.
> 	(resort_method_name_cmp): Ditto.
> 	* fortran/interface.c (pair_cmp): Ditto.

Note, c-family, cp and fortran have their own ChangeLog files, so
the entries without those prefixes need to go into each one and can't
refer to other ChangeLog through Ditto/Likewise etc.
Typo in symmteric.

That said, is this actually really a problem?  I mean, is qsort
allowed to call the comparison function with the same arguments?
I think lots of the comparison functions just assume that
for int cmpfn (const void *x, const void *y) x != y.
And if qsort can't call the comparison function with the same argument,
then perhaps the caller has some knowledge your checker does not, say
that the entries that would compare equal by the comparison function
simply can't appear in the array (so the caller knows that the comparison
function should never return 0).

> --- a/gcc/tree-vrp.c
> +++ b/gcc/tree-vrp.c
> @@ -5882,7 +5882,9 @@ compare_case_labels (const void *p1, const void *p2)
>    else if (idx1 == idx2)
>      {
>        /* Make sure the default label is first in a group.  */
> -      if (!CASE_LOW (ci1->expr))
> +      if (!CASE_LOW (ci1->expr) && !CASE_LOW (ci2->expr))
> +	return 0;
> +      else if (!CASE_LOW (ci1->expr))
>  	return -1;
>        else if (!CASE_LOW (ci2->expr))
>  	return 1;
> -- 
> 1.9.1

Say here, we know there is at most one default label in a switch, never
more.  So, unless qsort is allowed to call compare_case_labels
with p1 == p2 (which really doesn't make sense), this case just won't
happen.

	Jakub

  reply	other threads:[~2015-12-17 11:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-17  8:55 [PATCH 0/5] Fix qsort " Yury Gribov
2015-12-17  8:58 ` [PATCH 1/5] Fix asymmetric " Yury Gribov
2015-12-17 11:39   ` Jakub Jelinek [this message]
2015-12-17 12:04     ` Yury Gribov
2015-12-18 19:40       ` Yury Gribov
2015-12-18 20:07         ` Jakub Jelinek
2015-12-18 20:09           ` Yury Gribov
2015-12-17 11:41   ` Richard Biener
2015-12-17 11:47     ` Yury Gribov
2015-12-17 11:57       ` Jakub Jelinek
2015-12-17 11:59       ` Richard Biener
2015-12-17 12:14         ` Yury Gribov
2015-12-17 12:25           ` Richard Biener
2015-12-17 12:36             ` Yury Gribov
2015-12-17 11:59   ` Andrey Belevantsev
2015-12-17 12:12     ` Yury Gribov
2015-12-17 12:48       ` Andrey Belevantsev
2015-12-17 19:39   ` Andrew Pinski
2015-12-17 22:00   ` Jason Merrill
2015-12-17  8:59 ` [PATCH 2/5] Fix more " Yury Gribov
2015-12-17  9:00 ` [PATCH 3/5] "Fix" intransitive comparison in reload_pseudo_compare_func Yury Gribov
2015-12-17 19:36   ` Vladimir Makarov
2015-12-18 19:50     ` Yury Gribov
2015-12-17  9:02 ` [PATCH 4/5] Fix intransitive comparison in compare_access_positions Yury Gribov
2015-12-17 14:58   ` Martin Jambor
2015-12-17  9:03 ` [PATCH 5/5] Fix intransitive comparison in dr_group_sort_cmp Yury Gribov
2015-12-17 11:57   ` Richard Biener
2015-12-17 12:33     ` Yury Gribov
2015-12-17 12:51       ` Richard Biener
2015-12-18 20:19         ` Yury Gribov
2015-12-18 22:30           ` Yuri Gribov
2015-12-25 11:42             ` Yury Gribov
2016-01-08  8:23             ` Richard Biener

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=20151217113903.GS18720@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=abel@ispras.ru \
    --cc=amacleod@redhat.com \
    --cc=dnovillo@google.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=geoffk@geoffk.org \
    --cc=jason@redhat.com \
    --cc=pinskia@gmail.com \
    --cc=rguenther@suse.de \
    --cc=steven@gcc.gnu.org \
    --cc=y.gribov@samsung.com \
    /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).