From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 125545 invoked by alias); 17 Dec 2015 11:39:20 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 125515 invoked by uid 89); 17 Dec 2015 11:39:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.5 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=qsort, Yury, yury, tetra2005gmailcom X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 17 Dec 2015 11:39:16 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 9FBA03BF558; Thu, 17 Dec 2015 11:39:14 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-142.phx2.redhat.com [10.3.113.142]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBHBdCgr029466 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 17 Dec 2015 06:39:13 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id tBHBd8DA019280; Thu, 17 Dec 2015 12:39:08 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id tBHBd3wa019279; Thu, 17 Dec 2015 12:39:03 +0100 Date: Thu, 17 Dec 2015 11:39:00 -0000 From: Jakub Jelinek To: Yury Gribov Cc: GCC Patches , Andrey Belevantsev , Andrew MacLeod , Andrew Pinski , Diego Novillo , Geoff Keating , Jason Merrill , Richard Biener , Steven Bosscher Subject: Re: [PATCH 1/5] Fix asymmetric comparison functions Message-ID: <20151217113903.GS18720@tucnak.redhat.com> Reply-To: Jakub Jelinek References: <5672787D.6040105@samsung.com> <56727936.4030605@samsung.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <56727936.4030605@samsung.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes X-SW-Source: 2015-12/txt/msg01736.txt.bz2 On Thu, Dec 17, 2015 at 11:58:30AM +0300, Yury Gribov wrote: > 2015-12-17 Yury Gribov > > * 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