From patchwork Tue Jan 7 00:01:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 104199 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AAB083858D21 for ; Tue, 7 Jan 2025 00:02:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AAB083858D21 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from arjuna.pair.com (arjuna.pair.com [209.68.5.131]) by sourceware.org (Postfix) with ESMTPS id D66493858D28 for ; Tue, 7 Jan 2025 00:01:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D66493858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=bitrange.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bitrange.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D66493858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.68.5.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736208071; cv=none; b=WZbsOhezuGDuVY8a+r0L+4tTjluGHbv2lYzGro9rgwSUvVgomhIFzROQlzb7C56NF/7waV0Kdm7NCitU5/iwv+KCRN8e1L1AQdFzhSV2a8IpiUc1Sl5x70EE7M6LVc+1m9i2q0OBp7ClUnXu3dQ5WgCj0l2JSpdgrC72l3JFKKQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736208071; c=relaxed/simple; bh=2zl3+4Zux21YvQ3qnD5Ya8moZh46o7qcsVg5Fdq5aPI=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=qnIFy87m1h8QONieFkgKPyjlfiG2NiOV6rhEdqCLW3Ficeob1meFyDUBizr4n2HiBFbhdUx8iioPZoewVjLoLyaj8sErYDnEpYKwiuInD3Lkfe5I3jKDwD0SN7hWDP/gTGJuxemdbweGVKxoI8e7COTpA5ONsq5WFtNGl/GIos0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D66493858D28 Received: by arjuna.pair.com (Postfix, from userid 3006) id 9F4568A7EE; Mon, 6 Jan 2025 19:01:10 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by arjuna.pair.com (Postfix) with ESMTP id 9ED718A591 for ; Mon, 6 Jan 2025 19:01:10 -0500 (EST) Date: Mon, 6 Jan 2025 19:01:10 -0500 (EST) From: Hans-Peter Nilsson X-X-Sender: hp@arjuna.pair.com To: gcc-patches@gcc.gnu.org Subject: [PATCH] c-pretty-print.cc (pp_c_tree_decl_identifier): Strip private name encoding, PR118303 Message-ID: User-Agent: Alpine 2.20.16 (BSF 172 2016-09-29) MIME-Version: 1.0 X-Scanned-By: mailmunge 3.11 on 209.68.5.131 X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, 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: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Regtested native x86_64-linux. Also tested mmix-knuth-mmixware, where it fixes ONE testcase, but one which is a regression on master. The PR component is currently ipa, changed from the original middle-end. IIUC this bug-fix doesn't fit the ipa category IMHO, but rather more general tree-optimization or rather middle-end, to which I'll change the component unless I see a reason for this fitting ipa stated. Ok to commit? -- >8 -- This is a part of PR118303. It fixes FAIL: gcc.dg/analyzer/CVE-2005-1689-minimal.c (test for excess errors) FAIL: gcc.dg/analyzer/CVE-2005-1689-minimal.c inbuf.data (test for warnings, line 62) for targets where the parameter on that line is subject to TARGET_CALLEE_COPIES being true. c-family: PR middle-end/118303 * c-pretty-print.cc (c_pretty_printer::primary_expression) : Call primary_expression for all SSA_NAME_VAR nodes and instead move the DECL_ARTIFICIAL private name stripping to... (pp_c_tree_decl_identifier): ...here. --- gcc/c-family/c-pretty-print.cc | 39 +++++++++++++--------------------- 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/gcc/c-family/c-pretty-print.cc b/gcc/c-family/c-pretty-print.cc index 22a71d1e3558..0b6810e12242 100644 --- a/gcc/c-family/c-pretty-print.cc +++ b/gcc/c-family/c-pretty-print.cc @@ -1398,29 +1398,7 @@ c_pretty_printer::primary_expression (tree e) case SSA_NAME: if (SSA_NAME_VAR (e)) - { - tree var = SSA_NAME_VAR (e); - if (tree id = SSA_NAME_IDENTIFIER (e)) - { - const char *name = IDENTIFIER_POINTER (id); - const char *dot; - if (DECL_ARTIFICIAL (var) && (dot = strchr (name, '.'))) - { - /* Print the name without the . suffix (such as in VLAs). - Use pp_c_identifier so that it can be converted into - the appropriate encoding. */ - size_t size = dot - name; - char *ident = XALLOCAVEC (char, size + 1); - memcpy (ident, name, size); - ident[size] = '\0'; - pp_c_identifier (this, ident); - } - else - primary_expression (var); - } - else - primary_expression (var); - } + primary_expression (SSA_NAME_VAR (e)); else if (gimple_assign_single_p (SSA_NAME_DEF_STMT (e))) { /* Print only the right side of the GIMPLE assignment. */ @@ -3033,7 +3011,20 @@ pp_c_tree_decl_identifier (c_pretty_printer *pp, tree t) gcc_assert (DECL_P (t)); if (DECL_NAME (t)) - name = IDENTIFIER_POINTER (DECL_NAME (t)); + { + const char *dot; + name = IDENTIFIER_POINTER (DECL_NAME (t)); + if (DECL_ARTIFICIAL (t) && (dot = strchr (name, '.'))) + { + /* Print the name without the . suffix (such as in VLAs and + callee-copied parameters). */ + size_t size = dot - name; + char *ident = XALLOCAVEC (char, size + 1); + memcpy (ident, name, size); + ident[size] = '\0'; + name = ident; + } + } else { static char xname[8];