From patchwork Thu May 18 18:55:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 100121 Delivered-To: patch@linaro.org Received: by 10.182.142.97 with SMTP id rv1csp815614obb; Thu, 18 May 2017 11:55:23 -0700 (PDT) X-Received: by 10.99.147.67 with SMTP id w3mr5962936pgm.145.1495133723254; Thu, 18 May 2017 11:55:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495133723; cv=none; d=google.com; s=arc-20160816; b=vON7QLYXafObOh0sleWJw0suHFzgWi/aRj/noLEKn6Zrc5Tx5BVmL2THPF7tOPUFzP VGgFPU/MzP4Pskz2HoqyuiHvH2zLmHF5Va1OXwNIZ2qxVWwHrb43gc/6Wnx5dETkGZBE 9JosooOqHWTq9th6UBlMmEZGankKxr8k+K0ei/IXqLF8UMzXLtX/yNA7vg5ke0CZsmmX G+OmVP4RDtwG9IHoOhGkuYqnxsGFqMOCA0qIx9mKvudNo3S/V6zTMB9ZnqAH9UfZEAOE WdIYKB/CWPfybNnfUJWgB0Cy0AJ+SPEaz+WUw7dZg/uXdyVR74qeD53+FPszFN6wCq/V B77Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:subject:message-id:date:from:mime-version:delivered-to:sender :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=35m2wn+DcZCEeqNcnBkDZktawJCaAN8vic+5yner3Xk=; b=LZwg5sNxDWolYuqgDhQsNzRRHBqLQ+a7Ky2BKyReMdMPgRdB8QEopH5SqReQP5sduD I24NKG34tVTBuxzcvwjWf82oNeFaNXVXSaaLgTCa+Tsrd6nidi+BSa81oIrhyfP0RJP1 Za13JW0qo2IQ2/S3UU+I2eOywsKd+wvwvDOLjhRE56fTfnsn/eVBoJLgcHlXX9tB7p5x 8kUOCiVeaZOQutImb3kid9yll5D77bJCkqbr2DpZFm+hUzIlFkd+VaxEdm+grLzgxzsD DPrxHjsPqZkkee1RLAQuSWTwbziu1nfzNTGH1Yk2cf3CIB00n0xjImgAZfuDmJ/L87ZJ KC2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-453984-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-453984-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 61si5756683plz.198.2017.05.18.11.55.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 11:55:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-453984-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-453984-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-453984-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=yerv3ZQCWCJX07zLBRuLefph2vIHaAec+GLI3MjZ9cqTy2 4hYBIMLr+jTETqiSFRChb0nrR5xH7HkcNbVu5ee/K0bSLy1bV4pkOYLDIsxG2U0E PNS0wSXNxcRYFMMGUdjvFE2n0KB9AJ8CBZ92IIXqsKHmS0cmd8a+Y4LQR2L+4= 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 :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=n7HdHprCl7byqT8c22GvVeIJNaY=; b=GhDaYOkz9JUugnT3eHDX 8TkcRImtP1UX9ksmbm68SoO7FZ4uVyIlPpL/olmFM5+758a6mkQlvEuxsg4+FCbm qmcqGp95e0m2nAIrW3jtl/DQfSpbBtc4RpLxvM967MY+U2HteFx46Z2/5eNyOQE3 oWrBjbou58kBTE6J5DFWbL8= Received: (qmail 125038 invoked by alias); 18 May 2017 18:55:06 -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 122613 invoked by uid 89); 18 May 2017 18:55:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.2 required=5.0 tests=AWL, BAYES_00, 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=hist, Warns X-HELO: mail-it0-f41.google.com Received: from mail-it0-f41.google.com (HELO mail-it0-f41.google.com) (209.85.214.41) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 18 May 2017 18:55:01 +0000 Received: by mail-it0-f41.google.com with SMTP id o5so105954210ith.1 for ; Thu, 18 May 2017 11:55:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=8BwfhY6wFAocZVIp/rsJqllM74KyoAGs/TEYHSciXGQ=; b=Ggha6KqKjXxWGtLiyw3E+ukx5yNRz8QU25yZ+cUCoE4FOc2+c3d0Xci68DtNsjQvaC RHVyH1SKbUQ9A6hkUFd5iW+qLg7yRWZh/tKo2gMPUC7Ed3SP3IOWTBniO0Cl73PdaZma 8fGUQFFwcbciXyJlDhlM+vzjEojxvJd/YMivErRESl3Eve8l83nYxoM4aDCMGjeT4Dmo FfC7u2Rs/d7V9e3KT5KeLgdThhAnrlXhbV3fhuyB2oDhDNBzH1HcovfAPddV0PTdH2fr 8sLLqtvCaCloKWzdczEkgLYWipAKFAivt89BhEJDDUxWLDdpCDKQA4mdCA5tT+c5IfTt R/5g== X-Gm-Message-State: AODbwcDxWRLbuPeMsKpy7VXatpersMgsbnwz4bb8d57yc/8akim3dxcM j8XnQJfxw1JWob5LVy9NdbO3DuemDor/sXPQDA== X-Received: by 10.36.79.6 with SMTP id c6mr6491365itb.45.1495133702577; Thu, 18 May 2017 11:55:02 -0700 (PDT) MIME-Version: 1.0 Received: by 10.107.25.5 with HTTP; Thu, 18 May 2017 11:55:02 -0700 (PDT) From: Prathamesh Kulkarni Date: Fri, 19 May 2017 00:25:02 +0530 Message-ID: Subject: PR80806 To: gcc Patches , Richard Biener X-IsSubscribed: yes 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 ? There were following fallouts observed during bootstrap build: * double-int.c (div_and_round_double): Warning emitted 'den' set but not used for following call to memset: memset (den, 0, sizeof den); I assume the warning is correct since there's immediately call to: encode (den, lden, hden); and encode overwrites all the contents of den. Should the above call to memset be removed from the source ? * tree-streamer.c (streamer_check_handled_ts_structures) The function defines a local array bool handled_p[LAST_TS_ENUM]; and the warning is emitted for: memset (&handled_p, 0, sizeof (handled_p)); That's because the function then initializes each element of the array handled_p to true making the memset call redundant. I am not sure if warning for the above case is a good idea ? The call to memset() seems deliberate, to initialize all elements to 0, and later assert checks if all the elements were explicitly set to true. * value-prof.c (free_hist): Warns for the call to memset: static int free_hist (void **slot, void *data ATTRIBUTE_UNUSED) { histogram_value hist = *(histogram_value *) slot; free (hist->hvalue.counters); if (flag_checking) memset (hist, 0xab, sizeof (*hist)); free (hist); return 1; } Assuming flag_checking was true, the call to memset would be dead anyway since it would be immediately freed ? Um, I don't understand the purpose of memset in the above function. * testsuite fallout I verified regressing test-cases were not false positives and added -Wno-unused-but-set-variable. Thanks, Prathamesh diff --git a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c index 895a50e2677..6cbcc419976 100644 --- a/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c +++ b/gcc/testsuite/c-c++-common/Wsizeof-pointer-memaccess2.c @@ -1,7 +1,7 @@ /* Test -Wsizeof-pointer-memaccess warnings. */ /* { dg-do compile } */ -/* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -ftrack-macro-expansion=0" } */ -/* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -Wno-c++-compat -ftrack-macro-expansion=0" {target c} } */ +/* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -Wno-unused-but-set-variable -ftrack-macro-expansion=0" } */ +/* { dg-options "-Wall -O2 -Wno-sizeof-array-argument -Wno-c++-compat -Wno-unused-but-set-variable -ftrack-macro-expansion=0" {target c} } */ /* { dg-require-effective-target alloca } */ #define bos(ptr) __builtin_object_size (ptr, 1) diff --git a/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-vla-1.c b/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-vla-1.c index 87f5ef9d171..c42e3270db9 100644 --- a/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-vla-1.c +++ b/gcc/testsuite/gcc.dg/Wstrict-aliasing-bogus-vla-1.c @@ -1,6 +1,6 @@ /* PR 41673: bogus -Wstrict-aliasing warning from VLA dereference. */ /* { dg-do compile } */ -/* { dg-options "-std=gnu99 -O2 -Wall" } */ +/* { dg-options "-std=gnu99 -O2 -Wall -Wno-unused-but-set-variable" } */ /* { dg-require-effective-target alloca } */ int main(int argc, char *argv[]) diff --git a/gcc/testsuite/gcc.dg/attr-alloc_size.c b/gcc/testsuite/gcc.dg/attr-alloc_size.c index f50ba7c53db..8d71b3a4e6d 100644 --- a/gcc/testsuite/gcc.dg/attr-alloc_size.c +++ b/gcc/testsuite/gcc.dg/attr-alloc_size.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */ +/* { dg-options "-O2 -Wall -Wno-unused-but-set-variable -ftrack-macro-expansion=0" } */ extern void abort (void); diff --git a/gcc/testsuite/gcc.dg/pr79715.c b/gcc/testsuite/gcc.dg/pr79715.c index 0f0f90f7122..cd59f6dbf14 100644 --- a/gcc/testsuite/gcc.dg/pr79715.c +++ b/gcc/testsuite/gcc.dg/pr79715.c @@ -1,7 +1,7 @@ /* PR tree-optimization/79715 - hand-rolled strdup with unused result not eliminated { dg-do compile } - { dg-options "-O2 -Wall -fdump-tree-optimized" } */ + { dg-options "-O2 -Wall -Wno-unused-but-set-variable -fdump-tree-optimized" } */ void f (const char *s) { diff --git a/gcc/testsuite/gcc.dg/pr80806.c b/gcc/testsuite/gcc.dg/pr80806.c new file mode 100644 index 00000000000..551555c8fd1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr80806.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall" } */ + +void f1(void) +{ + char *p = __builtin_malloc (10); + __builtin_memset (p, 0, 10); /* { dg-warning "'p' set but not used" } */ +} + +void f2(void) +{ + char buf[10]; + __builtin_memset (buf, 0, 10); /* { dg-warning "'buf' set but not used" } */ +} diff --git a/gcc/testsuite/gcc.dg/torture/Wsizeof-pointer-memaccess1.c b/gcc/testsuite/gcc.dg/torture/Wsizeof-pointer-memaccess1.c index a73e45fb809..9ca9b287d25 100644 --- a/gcc/testsuite/gcc.dg/torture/Wsizeof-pointer-memaccess1.c +++ b/gcc/testsuite/gcc.dg/torture/Wsizeof-pointer-memaccess1.c @@ -1,6 +1,6 @@ /* Test -Wsizeof-pointer-memaccess warnings. */ /* { dg-do compile } */ -/* { dg-options "-Wall -Wno-sizeof-array-argument -Wno-stringop-overflow" } */ +/* { dg-options "-Wall -Wno-sizeof-array-argument -Wno-stringop-overflow -Wno-unused-but-set-variable" } */ /* Test just twice, once with -O0 non-fortified, once with -O2 fortified. */ /* { dg-skip-if "" { *-*-* } { "*" } { "-O0" "-O2" } } */ /* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c index 90230abe822..f6d583f8034 100644 --- a/gcc/tree-ssa-dse.c +++ b/gcc/tree-ssa-dse.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-cfgcleanup.h" #include "params.h" #include "alias.h" +#include "diagnostic.h" /* This file implements dead store elimination. @@ -742,7 +743,22 @@ dse_dom_walker::dse_optimize_stmt (gimple_stmt_iterator *gsi) } if (store_status == DSE_STORE_DEAD) - delete_dead_call (gsi); + { + tree ptr = gimple_call_arg (stmt, 0); + if (TREE_CODE (ptr) == SSA_NAME + || TREE_CODE (ptr) == ADDR_EXPR) + { + tree base = (TREE_CODE (ptr) == SSA_NAME) + ? SSA_NAME_VAR (ptr) + : TREE_OPERAND (ptr, 0); + + if (base && VAR_P (base)) + warning_at (gimple_location (stmt), + OPT_Wunused_but_set_variable, + "%qD set but not used", base); + } + delete_dead_call (gsi); + } return; }