From patchwork Thu Aug 31 12:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 137293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp212093vqu; Thu, 31 Aug 2023 05:38:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuFqz4fVh9ZVFp1o16d7xQIgZFo8in4j2gUu45OUS6j3lonUapMvIv92sYhUmHkeJkEgxC X-Received: by 2002:a17:907:6087:b0:9a1:d5de:5e3 with SMTP id ht7-20020a170907608700b009a1d5de05e3mr4100556ejc.54.1693485524783; Thu, 31 Aug 2023 05:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693485524; cv=none; d=google.com; s=arc-20160816; b=0IL5t12BnKhkEBxz4bvbPLNo5lWeF9mVS9yKpPlUuasMgoFgFX6qHYL0Hhd3pHRWJA 6G5l/ZjWCmpZ5mGRn/esR87BizyDkESXCJy2oHaFhSjwQQz6B1hzZugRQfxPabfZGly9 ovk8YdNcWqoiFz+TCAttdmofz3T/FigwnLpPCwG10h4L8FjgIWlfyAp8B/a+gD5dyUM+ gI5N9xq/VKvOcFMWOPGWey7ZKgj2+V4x8COis6qWxCdclDqTpg/YRoM3QMTQXERMC5PA xizenitWvwh/4JWbRPI+BcYXbvQQeo3ikXcAQBESl3OcX5zF0JQv+IInndnPvnLdO+jn BCHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=PZSfrl/5H0UQga4ygbaJfQii7wwZwAWxwwdVWE+rkr4=; fh=ZPc8FU+N4zVaOqtBSu8ucakGozooMAVUZZ5VYTiHlfM=; b=kE4JVi8DfTbzD2VhxhAP2XS3T7WHVfScTcyyKPLuketB6EUfDaoAZuhE9zX6rcDVb5 L7I0mjas7N01T8ZsjXVBPtmV+NCqVBVst+0OSyVktJaJje6/3Ebz83GwPo2F1YJdqh7+ hOsbFnTY6Kcw6jqmQfjDJUX6AvORCyucMuREKvlODhYKpR2ZM4g20Hzya4XN6DNHQuM5 XONSYdMsRz7nl6uo7f3E3MamRiYQjpgAylQiaLOPc83LoYENEu3+23eDGrp1B14+wQ/D 3Pn3fasHGVAqR3Q80EwxYVdHhtpvPynlkufjf/pQds6o188B3529y+K8ixHDrrBhY15u 2DDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uvM8cAGC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id lc2-20020a170906dfe200b0099b676cd0basi933449ejc.279.2023.08.31.05.38.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 31 Aug 2023 05:38:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=uvM8cAGC; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACE223858426 for ; Thu, 31 Aug 2023 12:38:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACE223858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693485523; bh=PZSfrl/5H0UQga4ygbaJfQii7wwZwAWxwwdVWE+rkr4=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=uvM8cAGC8Q3kgjtlzAC2TMk9hrZzI1tmpftN4O4ggoXxpZRCKRpi5bDwK+8X0Niae v18ezN1q4wV4uwbSpmPLLzOPHRGzygydNqaG4BbXVJbRznjh2xDKRyDqnyzQVyXY/z NkDf2Q03yeXqSfmJn9ZOxqw5WEt6uQEnRgZDb5zg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 94A013858D20 for ; Thu, 31 Aug 2023 12:38:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94A013858D20 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id B50FC1F895; Thu, 31 Aug 2023 12:37:59 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id AEA742C142; Thu, 31 Aug 2023 12:37:59 +0000 (UTC) Date: Thu, 31 Aug 2023 12:37:59 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jakub Jelinek , polacek@redhat.com Subject: [PATCH] middle-end/111253 - partly revert r11-6508-gabb1b6058c09a7 User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230831123843.ACE223858426@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775748277772630813 X-GMAIL-MSGID: 1775748277772630813 The following keeps dumping SSA def stmt RHS during diagnostic reporting only for gimple_assign_single_p defs which means memory loads. This avoids diagnostics containing PHI nodes like warning: 'realloc' called on pointer '*_42 = PHI .t_mem_caches' with nonzero offset 40 instead getting back the previous behavior: warning: 'realloc' called on pointer '*.t_mem_caches' with nonzero offset 40 Bootstrapped and tested on x86_64-unknown-linux-gnu, OK? Thanks, Richard. PR middle-end/111253 gcc/c-family/ * c-pretty-print.cc (c_pretty_printer::primary_expression): Only dump gimple_assign_single_p SSA def RHS. * gcc.dg/Wfree-nonheap-object-7.c: New testcase. --- gcc/c-family/c-pretty-print.cc | 7 ++++- gcc/testsuite/gcc.dg/Wfree-nonheap-object-7.c | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/Wfree-nonheap-object-7.c diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index 7536a7c471f..679aa766fe0 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -33,6 +33,9 @@ along with GCC; see the file COPYING3. If not see #include "langhooks.h" #include "options.h" #include "internal-fn.h" +#include "function.h" +#include "basic-block.h" +#include "gimple.h" /* The pretty-printer code is primarily designed to closely follow (GNU) C and C++ grammars. That is to be contrasted with spaghetti @@ -1380,12 +1383,14 @@ c_pretty_printer::primary_expression (tree e) else primary_expression (var); } - else + else if (gimple_assign_single_p (SSA_NAME_DEF_STMT (e))) { /* Print only the right side of the GIMPLE assignment. */ gimple *def_stmt = SSA_NAME_DEF_STMT (e); pp_gimple_stmt_1 (this, def_stmt, 0, TDF_RHS_ONLY); } + else + expression (e); break; default: diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-7.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-7.c new file mode 100644 index 00000000000..6116bfa4d8e --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-7.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wfree-nonheap-object" } */ + +struct local_caches *get_local_caches_lcs; +void *calloc(long, long); +void *realloc(); + +struct local_caches { + int *t_mem_caches; +}; + +struct local_caches *get_local_caches() { + if (get_local_caches_lcs) + return get_local_caches_lcs; + get_local_caches_lcs = calloc(1, 0); + return get_local_caches_lcs; +} + +void libtrace_ocache_free() { + struct local_caches lcs = *get_local_caches(), __trans_tmp_1 = lcs; + { + struct local_caches *lcs = &__trans_tmp_1; + lcs->t_mem_caches += 10; + __trans_tmp_1.t_mem_caches = realloc(__trans_tmp_1.t_mem_caches, sizeof(int)); // { dg-warning "called on pointer (?:(?!PHI).)*nonzero offset" } + } +}