From patchwork Wed Mar 16 00:45:27 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: asharif X-Patchwork-Id: 87137 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 033D5B70A4 for ; Wed, 16 Mar 2011 11:46:01 +1100 (EST) Received: (qmail 1016 invoked by alias); 16 Mar 2011 00:45:58 -0000 Received: (qmail 1008 invoked by uid 22791); 16 Mar 2011 00:45:58 -0000 X-SWARE-Spam-Status: No, hits=0.6 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Mar 2011 00:45:52 +0000 Received: from kpbe19.cbf.corp.google.com (kpbe19.cbf.corp.google.com [172.25.105.83]) by smtp-out.google.com with ESMTP id p2G0jnsX006762 for ; Tue, 15 Mar 2011 17:45:49 -0700 Received: from pwi8 (pwi8.prod.google.com [10.241.219.8]) by kpbe19.cbf.corp.google.com with ESMTP id p2G0jlYk026522 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=NOT) for ; Tue, 15 Mar 2011 17:45:47 -0700 Received: by pwi8 with SMTP id 8so227253pwi.36 for ; Tue, 15 Mar 2011 17:45:47 -0700 (PDT) Received: by 10.142.117.5 with SMTP id p5mr108213wfc.246.1300236347122; Tue, 15 Mar 2011 17:45:47 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.191.2 with HTTP; Tue, 15 Mar 2011 17:45:27 -0700 (PDT) In-Reply-To: References: From: asharif Date: Tue, 15 Mar 2011 17:45:27 -0700 Message-ID: Subject: Re: [PATCH] Add check before potentially dividing by 0 To: gcc-patches@gcc.gnu.org X-System-Of-Record: true Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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          * 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) 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 ==