From: Alexander Monakov <amonakov@ispras.ru>
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 14:30:00 -0000 [thread overview]
Message-ID: <20170721142947.5654-1-amonakov@ispras.ru> (raw)
In-Reply-To: <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;
}
--
1.8.3.1
next prev parent reply other threads:[~2017-07-21 14:30 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-15 20:49 [PATCH 0/6] qsort comparator consistency fixes Alexander Monakov
2017-07-15 20:48 ` [PATCH 3/6] lra-assigns.c: fix pseudo_compare_func Alexander Monakov
2017-07-19 6:50 ` Jeff Law
2017-07-15 20:49 ` [PATCH 2/6] gimple-ssa-store-merging.c: fix sort_by_bitpos Alexander Monakov
2017-07-19 6:50 ` Jeff Law
2017-07-22 11:15 ` Segher Boessenkool
2017-07-24 20:49 ` Alexander Monakov
2017-07-25 8:34 ` Kyrill Tkachov
2017-07-25 8:47 ` Richard Biener
2017-07-25 16:03 ` Alexander Monakov
2017-07-15 20:49 ` [PATCH 5/6] haifa-sched.c: give up qsort checking when autoprefetch heuristic is in use Alexander Monakov
2017-07-31 17:44 ` Jeff Law
2017-07-15 20:49 ` [PATCH 6/6] qsort comparator consistency checking Alexander Monakov
2017-07-31 18:06 ` Jeff Law
2017-07-31 18:28 ` Alexander Monakov
2017-08-02 17:16 ` Jeff Law
2017-08-02 17:29 ` Jeff Law
2017-08-02 18:00 ` Alexander Monakov
2017-08-02 18:08 ` Jeff Law
2017-08-03 14:25 ` Alexander Monakov
2017-08-03 15:33 ` Jeff Law
2017-08-03 15:53 ` Jakub Jelinek
2017-08-03 16:23 ` Alexander Monakov
2017-08-03 16:27 ` Oleg Endo
2017-08-03 16:31 ` Alexander Monakov
2017-08-03 16:35 ` Oleg Endo
2017-08-03 16:28 ` Jakub Jelinek
2017-08-07 14:07 ` Pedro Alves
2017-08-09 16:35 ` Jeff Law
2017-08-10 13:35 ` Alexander Monakov
2017-08-24 6:27 ` Jeff Law
2017-08-09 16:31 ` Jeff Law
2017-07-15 20:49 ` [PATCH 1/6] tree-vrp: fix compare_assert_loc qsort comparator Alexander Monakov
2017-07-19 6:51 ` Jeff Law
2017-07-15 20:49 ` [PATCH 4/6] lra-assigns.c: give up on qsort checking in assign_by_spills Alexander Monakov
2017-07-18 19:51 ` Yuri Gribov
2017-07-31 17:42 ` Jeff Law
2017-07-21 14:30 ` Alexander Monakov [this message]
2017-07-23 11:39 ` [PATCH 7/6] fortran: fix pair_cmp qsort comparator Thomas Koenig
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=20170721142947.5654-1-amonakov@ispras.ru \
--to=amonakov@ispras.ru \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.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).