From patchwork Thu May 2 21:39:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1930887 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=arHxmvWo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVnQv5bnzz20fW for ; Fri, 3 May 2024 07:40:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00CAA3844748 for ; Thu, 2 May 2024 21:40:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id A34F63846400 for ; Thu, 2 May 2024 21:39:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A34F63846400 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A34F63846400 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714685983; cv=none; b=C9/9V3q5cvZWOIV6WqYPItEsxRpknVOK2sHDiSHof07i2FTWe2mQxC4UOro4haL/5+sXYF16Sq7NaCqxKsG74n5Pc6KLwbcN0oS7begYUMXQzlBWqX1ZtqNw2mF6R/UWBNyg/1kheG9uy4jTVo+HtjZk888JHLtxPzWV21hcPd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714685983; c=relaxed/simple; bh=b3vU463d3/vyEO7corJ2BsTeAAbvMR0EsugE9AaJW1k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VmtO/j1WY/r78YgOfw3ytKhUe55xA+wJaQOmWWNSz18U+8hCQ68AUjcDtKNPEX9d633Gd42/541ZnNWS2g75fPKqwLGY7qz2Zv8W26ueOZNUEcWP3nnVp/E/yHHqsFi6KwHI5V2ka9wBgRt2n2LuRkWE2Bydhgebu2ZXwNIZLG8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 442LcInH000754 for ; Thu, 2 May 2024 21:39:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=dKaj7aha9sNP5noPthVNSvcMu7H0PJRP3IYMHipOfmU=; b=ar HxmvWoGIdt/NCQnHY1BzyDMf/aJPfeZQNl4RQShcJU4aCsaxrJ2FGI7nI7wSGYOi FDCXQTf87G2GxQevRRu6gfhWHTC0FIU8Xk0kk2QTGiovovX2kAYV26L01T6O/DU/ H7BmZEdlFWMBQivamTG5zI0+ViERuGaGVNMM3DybCxounLsQbGkYcp8imTDFGz6Y EQpfmM+2NsM/TlkAloB2hkplVi9Nj73tY6xONWeFkEN4IynBzsqsDwEWZXVdcNDT wlm6oQ87bXg0lKDbdpORCGZ3s5EqVMGG1b7ThwVRd9RdtDYVo3+PWIO+3iBkwoqp 7nVK4e0fEMbWJ/5RnO7w== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3xvawbh60b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 02 May 2024 21:39:40 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 442LdTt5011400 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 2 May 2024 21:39:29 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Thu, 2 May 2024 14:39:29 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/3] Improve DECL_EXPR printing in .original [PR23872] Date: Thu, 2 May 2024 14:39:17 -0700 Message-ID: <20240502213918.2029860-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240502213918.2029860-1-quic_apinski@quicinc.com> References: <20240502213918.2029860-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: VNMm6KnXFN2IK93MgP3JTi3QkI-9k0zy X-Proofpoint-ORIG-GUID: VNMm6KnXFN2IK93MgP3JTi3QkI-9k0zy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-02_13,2024-05-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 phishscore=0 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 spamscore=0 clxscore=1015 adultscore=0 mlxlogscore=675 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2404010003 definitions=main-2405020145 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Right now we don't print that a DECL_EXPR and we get basically double output of the decls and it looks confusing. This fixes that. for the simple example: `void foo () { int result = 0;}` This gives: ``` { int result = 0; DECL_EXPR; } ``` Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-pretty-print.cc (dump_generic_node ): Print out `DECL_EXPR<...>` around the decl and update the call to print_declaration to pass false for new argument and pass 0 for the spacing. (print_declaration): Add argument is_stmt and don't print a semicolon nor the initializer. * tree-pretty-print.h (print_declaration): Add bool argument and default it to true. Signed-off-by: Andrew Pinski --- gcc/tree-pretty-print.cc | 18 +++++++++++------- gcc/tree-pretty-print.h | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc index f9ad8562078..825ba74443b 100644 --- a/gcc/tree-pretty-print.cc +++ b/gcc/tree-pretty-print.cc @@ -2917,8 +2917,9 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, break; case DECL_EXPR: - print_declaration (pp, DECL_EXPR_DECL (node), spc, flags); - is_stmt = false; + pp_string (pp, "DECL_EXPR<"); + print_declaration (pp, DECL_EXPR_DECL (node), 0, flags, false); + pp_greater (pp); break; case COND_EXPR: @@ -4151,10 +4152,11 @@ dump_generic_node (pretty_printer *pp, tree node, int spc, dump_flags_t flags, return spc; } -/* Print the declaration of a variable. */ +/* Print the declaration of a variable, T to PP starting with SPC spaces with FLAGS + and called as IS_STMT a statement or not. */ void -print_declaration (pretty_printer *pp, tree t, int spc, dump_flags_t flags) +print_declaration (pretty_printer *pp, tree t, int spc, dump_flags_t flags, bool is_stmt) { INDENT (spc); @@ -4162,7 +4164,8 @@ print_declaration (pretty_printer *pp, tree t, int spc, dump_flags_t flags) { pp_string(pp, "namelist "); dump_decl_name (pp, t, flags); - pp_semicolon (pp); + if (is_stmt) + pp_semicolon (pp); return; } @@ -4231,7 +4234,7 @@ print_declaration (pretty_printer *pp, tree t, int spc, dump_flags_t flags) if (TREE_CODE (t) != FUNCTION_DECL) { /* Print the initial value. */ - if (DECL_INITIAL (t)) + if (DECL_INITIAL (t) && is_stmt) { pp_space (pp); pp_equal (pp); @@ -4250,7 +4253,8 @@ print_declaration (pretty_printer *pp, tree t, int spc, dump_flags_t flags) pp_right_bracket (pp); } - pp_semicolon (pp); + if (is_stmt) + pp_semicolon (pp); } diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h index 0da6242629b..660c17410a9 100644 --- a/gcc/tree-pretty-print.h +++ b/gcc/tree-pretty-print.h @@ -47,7 +47,7 @@ extern void dump_omp_loop_non_rect_expr (pretty_printer *, tree, int, dump_flags_t); extern void print_omp_context_selector (FILE *, tree, dump_flags_t); extern int dump_generic_node (pretty_printer *, tree, int, dump_flags_t, bool); -extern void print_declaration (pretty_printer *, tree, int, dump_flags_t); +extern void print_declaration (pretty_printer *, tree, int, dump_flags_t, bool = true); extern int op_code_prio (enum tree_code); extern int op_prio (const_tree); extern const char *op_symbol_code (enum tree_code, dump_flags_t = TDF_NONE);