From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 68964 invoked by alias); 29 Jun 2017 21:45:59 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 68926 invoked by uid 89); 29 Jun 2017 21:45:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy= X-HELO: mail-qk0-f181.google.com Received: from mail-qk0-f181.google.com (HELO mail-qk0-f181.google.com) (209.85.220.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 29 Jun 2017 21:45:55 +0000 Received: by mail-qk0-f181.google.com with SMTP id p21so87674707qke.3 for ; Thu, 29 Jun 2017 14:45:55 -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:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=2djCmk+K4m1kDF/WQWN+30+Jt6daLNjihpN7iNniN/o=; b=PkyRDrVgGa7zhWlclxcOJMApw9tIVMwnwDc1EwDb2n3DvjI+wk7vG/xHqSov4KuZHS yKnk1JmkUUw57lNXM0McPL21RDsE/fkQrGo2kFdNxV2uG7dHC9HniNUqk4PP66g8S6fo 0z5Z0BDl4VAHZDEzdzwZPFYCxVR1RTrsiYyMTpbjpJ68ZT8foF9Fzbg1ZgLRrsuKm8BY Ab88gvbA2jz/4adZqucVLRUiurhkjIaqjrWxcxfiZoZu3jxTcVPvdzSocLZjonJjrSiw IbSeRjorURtrRSGYsMzG6Pu604/53+Z9ZJQIHvbrNFVHJICbzlQlMG6XHxS4CdZgRdD0 Q2QA== X-Gm-Message-State: AKS2vOzXcvbNMFV1T7NLbccslbkuyR30opQI8AiWKbV30NUemMRe34lU IAz+w9Z9a9ad2Q== X-Received: by 10.55.20.214 with SMTP id 83mr22712940qku.112.1498772753746; Thu, 29 Jun 2017 14:45:53 -0700 (PDT) Received: from localhost.localdomain (75-171-245-140.hlrn.qwest.net. [75.171.245.140]) by smtp.gmail.com with ESMTPSA id w43sm5156223qtc.48.2017.06.29.14.45.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jun 2017 14:45:53 -0700 (PDT) Subject: Re: PR80806 To: Jeff Law , Prathamesh Kulkarni , gcc Patches , Richard Biener References: <2dae09d9-8b97-d178-6af0-a5c56a66b9a8@gmail.com> From: Martin Sebor Message-ID: <83c080d9-bac4-7730-5d6b-5d57ac66839b@gmail.com> Date: Thu, 29 Jun 2017 21:45:00 -0000 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: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2017-06/txt/msg02332.txt.bz2 On 06/29/2017 12:05 PM, Jeff Law wrote: > On 06/29/2017 11:57 AM, Jeff Law wrote: >> On 05/23/2017 09:58 AM, Martin Sebor wrote: >>> On 05/18/2017 12:55 PM, Prathamesh Kulkarni wrote: >>>> Hi, >>>> The attached patch tries to fix PR80806 by warning when a variable is >>>> set using memset (and friends) but not used. I chose to warn in dse >>>> pass since dse would detect if the variable passed as 1st argument is >>>> a dead store. Does this approach look OK ? >>> >>> Detecting -Wunused-but-set-variable in the optimizer means that >>> the warning will not be issued without optimization. It also >>> means that the warning will trigger in cases where the variable >>> is used conditionally and the condition is subject to constant >>> propagation. For instance: >> Yea. There's definitely tradeoffs for implementing warnings early vs >> late. There's little doubt we could construct testcases where an early >> warning would miss cases that could be caught by a late warning. >> >> >>> >>> void sink (void*); >>> >>> void test (int i) >>> { >>> char buf[10]; // -Wunused-but-set-variable >>> memset (buf, 0, sizeof(buf)); >>> >>> if (i) >>> sink (buf); >>> } >>> >>> void f (void) >>> { >>> test (0); >>> } >>> >>> I suspect this would be considered a false positive by most users. >>> In my view, it would be more in line with the design of the warning >>> to enhance the front end to detect this case, and it would avoid >>> these issues. >> Given no knowledge of sink() here, don't we have to assume that buf is >> used? So, yea, I'd probably consider that a false positive. > Oh, wait, I missed the constant propagation. That makes this one less > clear cut in my mind -- it means its context sensitive. I could easily > argue either way on this one. Suppose buf were the small buffer in std::string and sink() some conditional use of the class, like in this more complicated code: void foo (std::string&); void bar (char*); void test (int i) { std::string s; // calls memset (s.buf, 0, sizeof s.buf) char array[100] = ""; if (i > 100) foo (s); // needs a large buffer else bar (array); // works with a small buffer } Variations on this idiom aren't uncommon. Martin