This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Add check before potentially dividing by 0
- From: asharif <asharif at gcc dot gnu dot org>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 15 Mar 2011 17:45:27 -0700
- Subject: Re: [PATCH] Add check before potentially dividing by 0
- References: <AANLkTinbOe+ozP62SoctrOp3td=2SDK3wCyBiw3MNYf=@mail.gmail.com>
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.
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 ==
NODE_FREQUENCY_UNLIKELY_EXECUTED)