public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH]: Guard division by zero in ipa-icf dumps
@ 2014-10-24  6:27 Uros Bizjak
  0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2014-10-24  6:27 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth, Jakub Jelinek, Martin Liska

[-- Attachment #1: Type: text/plain, Size: 276 bytes --]

Hello!

2014-10-24  Martin Liska  <mliska@suse.cz>

    * ipa-icf.c (sem_item_optimizer::parse_nonsingleton_classes): Guard
    division by zero in dumps.
    (sem_item_optimizer::merge_classes): Ditto.

Tested on alphaev68-linux-gnu, committed to mainline as obvious.

Uros.

[-- Attachment #2: p.diff.txt --]
[-- Type: text/plain, Size: 1657 bytes --]

diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c
index d1238a4..e7a293e 100644
--- a/gcc/ipa-icf.c
+++ b/gcc/ipa-icf.c
@@ -1736,7 +1736,7 @@ sem_item_optimizer::parse_nonsingleton_classes (void)
 
   if (dump_file)
     fprintf (dump_file, "Init called for %u items (%.2f%%).\n", init_called_count,
-	     100.0f * init_called_count / m_items.length ());
+	     m_items.length () ? 100.0f * init_called_count / m_items.length (): 0.0f);
 }
 
 /* Equality function for semantic items is used to subdivide existing
@@ -2196,14 +2196,15 @@ sem_item_optimizer::merge_classes (unsigned int prev_class_count)
       fprintf (dump_file, "Congruent classes before: %u, after: %u\n",
 	       prev_class_count, class_count);
       fprintf (dump_file, "Average class size before: %.2f, after: %.2f\n",
-	       1.0f * item_count / prev_class_count,
-	       1.0f * item_count / class_count);
+	       prev_class_count ? 1.0f * item_count / prev_class_count : 0.0f,
+	       class_count ? 1.0f * item_count / class_count : 0.0f);
       fprintf (dump_file, "Average non-singular class size: %.2f, count: %u\n",
-	       1.0f * non_singular_classes_sum / non_singular_classes_count,
+	       non_singular_classes_count ? 1.0f * non_singular_classes_sum /
+	       non_singular_classes_count : 0.0f,
 	       non_singular_classes_count);
       fprintf (dump_file, "Equal symbols: %u\n", equal_items);
       fprintf (dump_file, "Fraction of visited symbols: %.2f%%\n\n",
-	       100.0f * equal_items / item_count);
+	       item_count ? 100.0f * equal_items / item_count : 0.0f);
     }
 
   for (hash_table<congruence_class_group_hash>::iterator it = m_classes.begin ();


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-10-24  6:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-24  6:27 [PATCH]: Guard division by zero in ipa-icf dumps Uros Bizjak

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).