From patchwork Fri Jul 21 14:29:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Monakov X-Patchwork-Id: 792152 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-458657-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="f3PFA1Qs"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xDY9K320Bz9sNx for ; Sat, 22 Jul 2017 00:31:12 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references; q=dns; s= default; b=ITWk3FRaas/ovSIaIhSGO9CAM0T++xzOfLTI1vkpzR/PjpDSwtqMN 7SOGkJXw3vTUt3P3Aw49vafDKLeKPhnIfUSxI3U26g7FqLN2uj7CIEvAP3OR6w/b 9E+HOWqCMpKnrwamySlmTrJ+EkmwCiWfi6L3Y2ObPqPXlvDCCmXNBI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:in-reply-to:references; s=default; bh=0lOfQ5lZuxGahZmWb0Ntm8mdlL4=; b=f3PFA1Qs+vT9QoiojYExDEVb1O37 r8du5rk2vdt0yRKMKU6iIjlEliYYJSVM9hWehYreh1BO0pjWJqTtLVxijC6Djy2m XL89jzZpJxOhaBJs6oGkEukYxmCG4YJKZrnDtCHmY5VYoqy1qdIIKdr1Q7TF9i/d 1SH76EdYWBGvf7k= Received: (qmail 58183 invoked by alias); 21 Jul 2017 14:30:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56477 invoked by uid 89); 21 Jul 2017 14:30:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1481, opposite X-Spam-User: qpsmtpd, 2 recipients X-HELO: smtp.ispras.ru Received: from bran.ispras.ru (HELO smtp.ispras.ru) (83.149.199.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 21 Jul 2017 14:30:21 +0000 Received: from monopod.intra.ispras.ru (monopod.intra.ispras.ru [10.10.3.121]) by smtp.ispras.ru (Postfix) with ESMTP id 83C945FB1B; Fri, 21 Jul 2017 17:30:18 +0300 (MSK) From: Alexander Monakov To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH 7/6] fortran: fix pair_cmp qsort comparator Date: Fri, 21 Jul 2017 17:29:47 +0300 Message-Id: <20170721142947.5654-1-amonakov@ispras.ru> In-Reply-To: <20170715204749.24398-1-amonakov@ispras.ru> References: <20170715204749.24398-1-amonakov@ispras.ru> Hello, The final tie-breaker in pair_cmp comparator looks strange, it correctly yields zero for equal expr->symtree-n.sym values, but for unequal values it produces 0 or 1. This would be correct for C++ STL-style comparators that require "less-than" predicate to be computed, but not for C qsort. The comment before the function seems to confirm that the intent was to indeed sort in ascending gfc_symbol order, but the code is doing mostly the opposite. Make the comparator properly anti-commutative by returning -1 in the last tie-breaker when appropriate. Bootstrapped and regtested on x86-64, OK for trunk? * interface.c (pair_cmp): Fix gfc_symbol comparison. Adjust comment. --- gcc/fortran/interface.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/interface.c b/gcc/fortran/interface.c index 6fe0647..13e2bdd 100644 --- a/gcc/fortran/interface.c +++ b/gcc/fortran/interface.c @@ -3294,7 +3294,7 @@ argpair; order: - p->a->expr == NULL - p->a->expr->expr_type != EXPR_VARIABLE - - growing p->a->expr->symbol. */ + - by gfc_symbol pointer value (larger first). */ static int pair_cmp (const void *p1, const void *p2) @@ -3320,6 +3320,8 @@ pair_cmp (const void *p1, const void *p2) } if (a2->expr->expr_type != EXPR_VARIABLE) return 1; + if (a1->expr->symtree->n.sym > a2->expr->symtree->n.sym) + return -1; return a1->expr->symtree->n.sym < a2->expr->symtree->n.sym; }