This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Add check before potentially dividing by 0


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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]