Patchwork Add check before potentially dividing by 0

login
register
mail settings
Submitter asharif
Date March 16, 2011, 12:45 a.m.
Message ID <AANLkTimphyNTTAvxNgiceJ263O5xgOeuSjbuKsSvApvL@mail.gmail.com>
Download mbox | patch
Permalink /patch/87137/
State New
Headers show

Comments

asharif - March 16, 2011, 12:45 a.m.
I have seen an ICE in 4.4.3 when a corrupted profile file causes a
division by 0 in gcc. This is the equivalent code in trunk and this
check should help fix it.
Thoughts?

2011-03-15  Ahmad Sharif  <asharif@google.com>

       * predict.c (probably_never_executed_bb_p): Add check to see
       whether profile_info->runs is equal to 0 before doing the division.
NODE_FREQUENCY_UNLIKELY_EXECUTED)

Patch

Index: predict.c
===================================================================
--- predict.c (revision 171019)
+++ predict.c (working copy)
@@ -200,7 +200,7 @@ 
 bool
 probably_never_executed_bb_p (const_basic_block bb)
 {
-  if (profile_info && flag_branch_probabilities)
+  if (profile_info && flag_branch_probabilities && profile_info->runs != 0)
     return ((bb->count + profile_info->runs / 2) / profile_info->runs) == 0;
   if ((!profile_info || !flag_branch_probabilities)
       && cgraph_node (current_function_decl)->frequency ==