From patchwork Mon Apr 24 21:07:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 754442 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBf784kL0z9s8Q for ; Tue, 25 Apr 2017 07:07:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="iACNdFP0"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=KqPtntQLkqC3hJ+ME OOS+mxu1lZJ0mwJ2wZjCsDgrLaRWEy7QaOghG7i0OXqH1euAGn2Devcvb2hhZaRL 4XI09XaDvf0rytSEIQfJ8MLo8M/iRQGvzkWnXaVMLsKGutjxy9aqY+BuLZlK7Ilf IsOW/PTPe1xaHC1auBHowCu3ZU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=D7R6WqCX/iXtw78tTRP3xdU 1Y1k=; b=iACNdFP0FbLZI63RsyDVDTYRjkY6Nnkq/HrsmdqHzxie8UFYwbds0aJ p+ACqCemUPEHTOSynh2hWcUtKKT1CI05BNHe6okDBoUpbrmiGwJ98vHGCNxKSkXq QO01Td0d+8FP7GPku+UPsBJq1YXwR1SGA9B4ti9F021Oyf2nf960= Received: (qmail 20865 invoked by alias); 24 Apr 2017 21:07:20 -0000 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 Received: (qmail 20827 invoked by uid 89); 24 Apr 2017 21:07:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=H*RU:209.85.216.194, Hx-spam-relays-external:209.85.216.194 X-HELO: mail-qt0-f194.google.com Received: from mail-qt0-f194.google.com (HELO mail-qt0-f194.google.com) (209.85.216.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Apr 2017 21:07:18 +0000 Received: by mail-qt0-f194.google.com with SMTP id t52so22373801qtb.3 for ; Mon, 24 Apr 2017 14:07:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=84xsVigM0CDNVdeW5RBVuQzjpHzrGeu7Sm98JG4rvzQ=; b=aecyr4o0jTsrRR1EYGoP/Y6LJofAexB+PRT6KR4akw34NRo+ftSB9AXiz7VjvQkhyO dMpl8Tmn8TwTam4xBKkSjEcmA4rPEbxBVhKQiv7NzxRastSo7xl0haqak/BoIw3BoCOP hy+yuuvYxcw19dcwCA7afZAFMlbq4546BZqhcYkv3n3kIOswPCBcMFJmUQYLpd/JCyk6 +vDEfJ3Z/HDfnoWgWItct4ZI1hNVoyDqdhiiJj6/PnNmUYnbMeA6It8/bLRVW8V9eXgM k9baa++hsOSe4qskWqfA9+RHAmFuzFoqan36tXFqepx5frO872a6Q1rS8Lde2kWkmRpO 6pvw== X-Gm-Message-State: AN3rC/7tIgtPk/0MFNz9sMwjXPHtSPRedw57yAd2j6brCwh8euEHOTSX ts7m8ZU009rZVMYO X-Received: by 10.200.36.131 with SMTP id s3mr30845795qts.289.1493068038329; Mon, 24 Apr 2017 14:07:18 -0700 (PDT) Received: from localhost.localdomain (75-166-101-229.hlrn.qwest.net. [75.166.101.229]) by smtp.gmail.com with ESMTPSA id v13sm13719750qtc.18.2017.04.24.14.07.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Apr 2017 14:07:17 -0700 (PDT) Subject: Re: [PATCH] squash spurious warnings in dominance.c To: Richard Biener References: Cc: Gcc Patch List From: Martin Sebor Message-ID: Date: Mon, 24 Apr 2017 15:07:15 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 04/24/2017 01:32 AM, Richard Biener wrote: > On Sat, Apr 22, 2017 at 2:51 AM, Martin Sebor wrote: >> Bug 80486 - spurious -Walloc-size-larger-than and >> -Wstringop-overflow in dominance.c during profiledbootstrap >> points out a number of warnings that show up in dominance.c >> during a profiledbootstrap. I'm pretty sure the warnings >> are due to the size check the C++ new expression introduces >> to avoid unsigned overflow before calling operator new, and >> by some optimization like jump threading introducing a branch >> with the call to the allocation function and memset with >> the excessive constant size. >> >> Two ways to avoid it come to mind: 1) use the libiberty >> XCNEWVEC and XNEWVEC macros instead of C++ new expressions, >> and 2) constraining the size variable to a valid range. >> >> Either of these approaches should result in better code than >> the new expression because they both eliminate the test for >> the overflow. Attached is a patch that implements (1). I >> chose it mainly because it seems in line with GCC's memory >> management policy and with avoiding exceptions. >> >> An alternate patch should be straightforward. Either add >> an assert like the one below or change the type of >> m_n_basic_blocks from size_t to unsigned. This approach, >> though less intrusive, will likely bring the warning back >> in ILP32 builds; I'm not sure if it matters. > > Please change m_n_basic_blocks (and local copies) from size_t > to unsigned int. This is an odd inconsistency that's worth fixing > in any case. Attached is this version of the patch. It also eliminates the warnings and passes profiledbootstrap/regression test on x86_64. Martin PR bootstrap/80486 - spurious -Walloc-size-larger-than and -Wstringop-overflow in dominance.c during profiledbootstrap gcc/ChangeLog: PR bootstrap/80486 * dominance.c (dom_info::m_n_basic_blocks): Change type to unsigned. (new_zero_array): Adjust signature. (dom_info::dom_init): Used unsigned rather that size_t. (dom_info::dom_info): Same. diff --git a/gcc/dominance.c b/gcc/dominance.c index c76e62e..1d4bd54 100644 --- a/gcc/dominance.c +++ b/gcc/dominance.c @@ -125,7 +125,7 @@ private: bitmap m_fake_exit_edge; /* Number of basic blocks in the function being compiled. */ - size_t m_n_basic_blocks; + unsigned m_n_basic_blocks; /* True, if we are computing postdominators (rather than dominators). */ bool m_reverse; @@ -148,7 +148,7 @@ void debug_dominance_tree (cdi_direction, basic_block); `x = new T[num] {};'. */ template -inline T *new_zero_array (size_t num) +inline T *new_zero_array (unsigned num) { T *result = new T[num]; memset (result, 0, sizeof (T) * num); @@ -160,14 +160,15 @@ inline T *new_zero_array (size_t num) void dom_info::dom_init (void) { - size_t num = m_n_basic_blocks; + unsigned num = m_n_basic_blocks; + m_dfs_parent = new_zero_array (num); m_dom = new_zero_array (num); m_path_min = new TBB[num]; m_key = new TBB[num]; m_set_size = new unsigned int[num]; - for (size_t i = 0; i < num; i++) + for (unsigned i = 0; i < num; i++) { m_path_min[i] = m_key[i] = i; m_set_size[i] = 1; @@ -221,13 +222,13 @@ dom_info::dom_info (function *fn, cdi_direction dir) dom_info::dom_info (vec region, cdi_direction dir) { m_n_basic_blocks = region.length (); - unsigned int nm1 = m_n_basic_blocks - 1; + unsigned nm1 = m_n_basic_blocks - 1; dom_init (); /* Determine max basic block index in region. */ int max_index = region[0]->index; - for (size_t i = 1; i <= nm1; i++) + for (unsigned i = 1; i <= nm1; i++) if (region[i]->index > max_index) max_index = region[i]->index; max_index += 1; /* set index on the first bb out of region. */