From patchwork Thu Mar 18 08:48:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1455792 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ulDHNhym; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F20ww2t72z9sWF for ; Fri, 19 Mar 2021 21:48:16 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A6673857C50; Fri, 19 Mar 2021 10:48:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A6673857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1616150893; bh=ed9CqDphGy7av7YNzcF26IzB/EFNDQhsYQV6gxp3iAU=; h=Resent-From:Resent-Date:Resent-To:Date:To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:Cc:From; b=ulDHNhymOyvXCxdpmh5HeTqqrwQDruJGyZT9My+F1G4T9NNFdiC1Ts0I0SGkRNL8t /MzV8coFV+iZoY4UMVAdcPqzuvH8x/+onKsfJtz2uAmGnyK0A8ei+fGUp//OMLtQJd iZuNsC398Zsyy2qqUVudvfMS5fZTnUhGDJ8fV6p8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D5B13385801A for ; Fri, 19 Mar 2021 10:48:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D5B13385801A Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-Up-SNppxNMy7dtT21QwpFg-1; Fri, 19 Mar 2021 06:48:06 -0400 X-MC-Unique: Up-SNppxNMy7dtT21QwpFg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E5434107B7CB; Fri, 19 Mar 2021 10:48:05 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-95.ams2.redhat.com [10.36.112.95]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24B2F1992D; Fri, 19 Mar 2021 10:48:01 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 12JAlxMl3418041 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 19 Mar 2021 11:47:59 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 12JAlwew3418040; Fri, 19 Mar 2021 11:47:58 +0100 Resent-From: Jakub Jelinek Resent-Date: Fri, 19 Mar 2021 11:47:58 +0100 Resent-Message-ID: <20210319104758.GV3748@tucnak> Resent-To: "Joseph S. Myers" , Marek Polacek , Jason Merrill , gcc-patches@gcc.gnu.org Date: Thu, 18 Mar 2021 09:48:12 +0100 To: "Joseph S. Myers" , Marek Polacek , Jason Merrill Subject: [PATCH] c-family: Fix PR94272 -fcompare-debug issue even for C [PR99230] Message-ID: <20210318084810.GP231854@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase results in -fcompare-debug failure. The problem is the similar like in PR94272 https://gcc.gnu.org/pipermail/gcc-patches/2020-March/542562.html When genericizing, with -g0 we have just a TREE_SIDE_EFFECTS DO_STMT in a branch of if, while with -g we have that wrapped into TREE_SIDE_EFFECTS STATEMENT_LIST containing DEBUG_BEGIN_STMT and that DO_STMT. The do loop is empty with 0 condition, so c_genericize_control_stmt turns it into an empty statement (without TREE_SIDE_EFFECTS). For -g0 that means that suddenly the if branch doesn't have side effects and is expanded differently. But with -g we still have TREE_SIDE_EFFECTS STATEMENT_LIST containing DEBUG_BEGIN_STMT and non-TREE_SIDE_EFFECTS stmt. The following patch fixes that by detecting this case and removing TREE_SIDE_EFFECTS. And, so that we don't duplicate the same code, changes the C++ FE to just call the c_genericize_control_stmt function that can now handle it. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-03-18 Jakub Jelinek PR debug/99230 * c-gimplify.c (c_genericize_control_stmt): Handle STATEMENT_LIST. * cp-gimplify.c (cp_genericize_r) : Remove special code, instead call c_genericize_control_stmt. * gcc.dg/pr99230.c: New test. Jakub --- gcc/c-family/c-gimplify.c.jj 2021-01-04 10:25:50.402102825 +0100 +++ gcc/c-family/c-gimplify.c 2021-03-17 19:19:20.052702095 +0100 @@ -497,6 +497,35 @@ c_genericize_control_stmt (tree *stmt_p, genericize_omp_for_stmt (stmt_p, walk_subtrees, data, func, lh); break; + case STATEMENT_LIST: + if (TREE_SIDE_EFFECTS (stmt)) + { + tree_stmt_iterator i; + int nondebug_stmts = 0; + bool clear_side_effects = true; + /* Genericization can clear TREE_SIDE_EFFECTS, e.g. when + transforming an IF_STMT into COND_EXPR. If such stmt + appears in a STATEMENT_LIST that contains only that + stmt and some DEBUG_BEGIN_STMTs, without -g where the + STATEMENT_LIST wouldn't be present at all the resulting + expression wouldn't have TREE_SIDE_EFFECTS set, so make sure + to clear it even on the STATEMENT_LIST in such cases. */ + for (i = tsi_start (stmt); !tsi_end_p (i); tsi_next (&i)) + { + tree t = tsi_stmt (i); + if (TREE_CODE (t) != DEBUG_BEGIN_STMT && nondebug_stmts < 2) + nondebug_stmts++; + walk_tree_1 (tsi_stmt_ptr (i), func, data, NULL, lh); + if (TREE_CODE (t) != DEBUG_BEGIN_STMT + && (nondebug_stmts > 1 || TREE_SIDE_EFFECTS (tsi_stmt (i)))) + clear_side_effects = false; + } + if (clear_side_effects) + TREE_SIDE_EFFECTS (stmt) = 0; + *walk_subtrees = 0; + } + break; + default: break; } --- gcc/cp/cp-gimplify.c.jj 2021-03-04 09:42:27.602123905 +0100 +++ gcc/cp/cp-gimplify.c 2021-03-17 19:38:42.743888589 +0100 @@ -1464,35 +1464,6 @@ cp_genericize_r (tree *stmt_p, int *walk walk_subtrees = 0; break; - case STATEMENT_LIST: - if (TREE_SIDE_EFFECTS (stmt)) - { - tree_stmt_iterator i; - int nondebug_stmts = 0; - bool clear_side_effects = true; - /* Genericization can clear TREE_SIDE_EFFECTS, e.g. when - transforming an IF_STMT into COND_EXPR. If such stmt - appears in a STATEMENT_LIST that contains only that - stmt and some DEBUG_BEGIN_STMTs, without -g where the - STATEMENT_LIST wouldn't be present at all the resulting - expression wouldn't have TREE_SIDE_EFFECTS set, so make sure - to clear it even on the STATEMENT_LIST in such cases. */ - for (i = tsi_start (stmt); !tsi_end_p (i); tsi_next (&i)) - { - tree t = tsi_stmt (i); - if (TREE_CODE (t) != DEBUG_BEGIN_STMT && nondebug_stmts < 2) - nondebug_stmts++; - cp_walk_tree (tsi_stmt_ptr (i), cp_genericize_r, data, NULL); - if (TREE_CODE (t) != DEBUG_BEGIN_STMT - && (nondebug_stmts > 1 || TREE_SIDE_EFFECTS (tsi_stmt (i)))) - clear_side_effects = false; - } - if (clear_side_effects) - TREE_SIDE_EFFECTS (stmt) = 0; - *walk_subtrees = 0; - } - break; - case OMP_DISTRIBUTE: /* Need to explicitly instantiate copy ctors on class iterators of composite distribute parallel for. */ @@ -1566,6 +1537,7 @@ cp_genericize_r (tree *stmt_p, int *walk case OMP_SIMD: case OMP_LOOP: case OACC_LOOP: + case STATEMENT_LIST: /* These cases are handled by shared code. */ c_genericize_control_stmt (stmt_p, walk_subtrees, data, cp_genericize_r, cp_walk_subtrees); --- gcc/testsuite/gcc.dg/pr99230.c.jj 2021-03-17 19:34:26.633711074 +0100 +++ gcc/testsuite/gcc.dg/pr99230.c 2021-03-17 19:33:30.210332887 +0100 @@ -0,0 +1,40 @@ +/* PR debug/99230 */ +/* { dg-do compile } */ +/* { dg-options "-O2 --param logical-op-non-short-circuit=0 -fcompare-debug --param=jump-table-max-growth-ratio-for-speed=5000" } */ + +extern void fn2 (void); +extern void fn3 (int); +int a, b; +void +fn1 (void) +{ + int c; + short d; + switch (a) { + case 22000: + fn2 (); + case 22300: + b = 0; + case 22600: + case 22601: + case 22900: + fn3 (1); + case 20100: + fn3 (2); + case 20200: + fn3 (3); + case 20300: + fn3 (4); + case 20400: + fn3 (5); + case 20310: + fn3 (4); + case 20410: + fn3 (5); + } + if (d || c) { + do + ; + while (0); + } +}