On 9/19/19 3:18 PM, Richard Biener wrote:
> On Thu, Sep 19, 2019 at 3:15 PM Alexander Monakov <amona...@ispras.ru> wrote:
>>
>> On Thu, 19 Sep 2019, Richard Biener wrote:
>>
>>>> Good point, there's a tested patch.
>>>
>>> OK.
>>
>> Hold on, is the new comparator really correct?
>>
>>
>> @@ -3384,20 +3372,11 @@ sort_congruence_classes_by_decl_uid (const void *a, 
>> const void *b)
>>  static int
>>  sort_congruence_class_groups_by_decl_uid (const void *a, const void *b)
>>  {
>> -  const congruence_class_group *g1
>> -    = *(const congruence_class_group * const *)a;
>> -  const congruence_class_group *g2
>> -    = *(const congruence_class_group * const *)b;
>> -
>> -  int uid1 = DECL_UID (g1->classes[0]->members[0]->decl);
>> -  int uid2 = DECL_UID (g2->classes[0]->members[0]->decl);
>> -
>> -  if (uid1 < uid2)
>> -    return -1;
>> -  else if (uid1 > uid2)
>> -    return 1;
>> -  else
>> -    return 0;
>> +  const std::pair<congruence_class_group *, int> *g1
>> +    = *(const std::pair<congruence_class_group *, int> *const *) a;
>> +  const std::pair<congruence_class_group *, int> *g2
>> +    = *(const std::pair<congruence_class_group *, int> *const *) b;
>> +  return g1->second - g2->second;
>>  }
>>
>>
>> AFAICT the vec holds pairs, not pointers to pairs, so why does the comparator
>> cast to a pointer-to-pointer-to-pair? Shouldn't it read
>>
>>   const std::pair<congruence_class_group *, int> *g1
>>     = (const std::pair<congruence_class_group *, int> *) a;
> 
> Indeed.  We need static type correctness for the comparator :/

Ooops, sorry for the mistake. I'm testing the following patch.
I checked in debugger that uids are valid for a simple test-case.

Martin

> 
> Richard.
> 
>> Thanks.
>> Alexander

>From 5f94530ee52b254a1e3cdfc0f4db4222a6b77a14 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Thu, 19 Sep 2019 15:27:20 +0200
Subject: [PATCH] Fix cast in sort_congruence_class_groups_by_decl_uid.

gcc/ChangeLog:

2019-09-19  Martin Liska  <mli...@suse.cz>

	* ipa-icf.c (sort_congruence_class_groups_by_decl_uid):
	Use proper casting.
---
 gcc/ipa-icf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index 59b7f8b1b9d..009aeb487dd 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -3373,9 +3373,9 @@ static int
 sort_congruence_class_groups_by_decl_uid (const void *a, const void *b)
 {
   const std::pair<congruence_class_group *, int> *g1
-    = *(const std::pair<congruence_class_group *, int> *const *) a;
+    = (const std::pair<congruence_class_group *, int> *) a;
   const std::pair<congruence_class_group *, int> *g2
-    = *(const std::pair<congruence_class_group *, int> *const *) b;
+    = (const std::pair<congruence_class_group *, int> *) b;
   return g1->second - g2->second;
 }
 
-- 
2.23.0

Reply via email to