From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 70D133858C20 for ; Fri, 4 Mar 2022 00:08:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 70D133858C20 Received: by mail-il1-x12d.google.com with SMTP id j5so5352370ila.2 for ; Thu, 03 Mar 2022 16:08:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=GsPcLsDF+IWvuLILhXeB7NqejVM8UWdTBgQDqaF7A40=; b=mwPW/Zwq8ja5oV892hLzaoEIQ9m8LiumSLM+bt+BmjZqYwxCduPNyGNVJKfb7AWYEL eWhnXITWrgfqGMNC4feh6MVI4sDW9Lrvz76Xp3ukljwUqG39OPvop1GEQ9XNA6ke17cO RAB94Av0s9xeW2g7jiE6igStEt7JfeScWFMolwU8wnS5COJxt47slge+Wj7QtdfLo4tR +ytwpZ0PKlFP1Ig9ScYn5jEFmezzMdQynwowUridcCyaYXxY4CyDaMKa16TlfERhLsYY xZ+muynayB/2JggNUvOiBLu2qFzEt9V/fmRkB1VXMu8X9JIdoFKIdSNR5+jgiVVUxIy6 v7eA== X-Gm-Message-State: AOAM53232LCGvfUO6n+Yk+YxwEkYUnYQYCGZDNgnX6ev7ukYahQBzMEg DF9pqlXs6hM23RCPRe5362s= X-Google-Smtp-Source: ABdhPJw7MMhcl+IlR5vmjQpfKoIQ48QxiK43H6JqQt5ZoiNZmQZXKO2+w8Wv1hy/dWJ7xAcT/yAAcw== X-Received: by 2002:a05:6e02:1b0f:b0:2c2:5fc3:1740 with SMTP id i15-20020a056e021b0f00b002c25fc31740mr33706747ilv.297.1646352512715; Thu, 03 Mar 2022 16:08:32 -0800 (PST) Received: from [192.168.0.41] (97-118-101-70.hlrn.qwest.net. [97.118.101.70]) by smtp.gmail.com with ESMTPSA id f4-20020a92b504000000b002c21ef70a81sm3449193ile.7.2022.03.03.16.08.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Mar 2022 16:08:32 -0800 (PST) Message-ID: <3a1b2fc6-a21a-14e4-c34f-b8b0c311d35f@gmail.com> Date: Thu, 3 Mar 2022 17:08:30 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH] call mark_dfs_back_edges() before testing EDGE_DFS_BACK [PR104761] Content-Language: en-US To: Jakub Jelinek , Richard Biener , Jeff Law Cc: gcc-patches References: From: Martin Sebor In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 04 Mar 2022 00:08:35 -0000 On 3/3/22 01:01, Jakub Jelinek wrote: > On Wed, Mar 02, 2022 at 04:15:09PM -0700, Martin Sebor via Gcc-patches wrote: >> The -Wdangling-pointer code tests the EDGE_DFS_BACK but the pass never >> calls the mark_dfs_back_edges() function that initializes the bit (I >> didn't know about it). As a result the bit is not set when expected, >> which can cause false positives under the right conditions. > > Not a review because I also had to look up what computes EDGE_DFS_BACK, > so I don't feel the right person to ack the patch. > > So, just a few questions. > > The code in question is: > auto gsi = gsi_for_stmt (use_stmt); > > auto_bitmap visited; > > /* A use statement in the last basic block in a function or one that > falls through to it is after any other prior clobber of the used > variable unless it's followed by a clobber of the same variable. */ > basic_block bb = use_bb; > while (bb != inval_bb > && single_succ_p (bb) > && !(single_succ_edge (bb)->flags & (EDGE_EH|EDGE_DFS_BACK))) > { > if (!bitmap_set_bit (visited, bb->index)) > /* Avoid cycles. */ > return true; > > for (; !gsi_end_p (gsi); gsi_next_nondebug (&gsi)) > { > gimple *stmt = gsi_stmt (gsi); > if (gimple_clobber_p (stmt)) > { > if (clobvar == gimple_assign_lhs (stmt)) > /* The use is followed by a clobber. */ > return false; > } > } > > bb = single_succ (bb); > gsi = gsi_start_bb (bb); > } > > 1) shouldn't it give up for EDGE_ABNORMAL too? I mean, e.g. > following a non-local goto forced edge from a noreturn call > to a non-local label (if there is just one) doesn't seem > right to me Possibly yes. I can add it but I don't have a lot of experience with these bits so if you can suggest a test case to exercise this that would be helpful. > 2) if EDGE_DFS_BACK is computed and 1) is done, is there any > reason why you need 2 levels of protection, i.e. the EDGE_DFS_BACK > check as well as the visited bitmap (and having them use > very different answers, if EDGE_DFS_BACK is seen, the function > will return false, if visited bitmap has a bb, it will return true)? > Can't the visited bitmap go away? Possibly. As I said above, I don't have enough experience with these bits to make (and test) the changes quickly, or enough bandwidth to come up to speed on them. Please feel free to make these improvements. > 3) I'm concerned about compile time with the above, consider you have > 1000000 use_stmts and 1000000 corresponding inv_stmts and in each > case you enter this loop and go through a series of very large basic > blocks that don't clobber those stmts; shouldn't it bail out > (return false) after walking some param > controlled number of non-debug stmts (say 1000 by default)? > There is an early exit if > if (dominated_by_p (CDI_DOMINATORS, use_bb, inval_bb)) > return true; > (I admit I haven't read the code what happens if there is more than > one clobber for the same variable) I tend to agree that the loop is less than optimal. But before imposing another arbitrary limit my preference would be to see if it could be made more efficient. Without thinking about it too hard, it seems that with some efficient lookup table a single traversal per function should be sufficient. The first time through populate the table with the clobbered variables along the path from use_bb and each subsequent time just look up clobvar in the table. But I have to use up the rest of my 2021 PTO next week before I lose it and I don't expect to have the cycles to work on this anytime soon. Martin > >> The attached patch adds a call to the warning pass to initialize >> the bit. Tested on x86_64-linux. >> >> Martin > >> Call mark_dfs_back_edges before testing EDGE_DFS_BACK [PR104761]. >> >> Resolves: >> PR middle-end/104761 - bogus -Wdangling-pointer with cleanup and infinite loop >> >> gcc/ChangeLog: >> >> PR middle-end/104761 >> * gimple-ssa-warn-access.cc (pass_waccess::execute): Call >> mark_dfs_back_edges. >> >> gcc/testsuite/ChangeLog: >> >> PR middle-end/104761 >> * g++.dg/warn/Wdangling-pointer-4.C: New test. >> * gcc.dg/Wdangling-pointer-4.c: New test. >> >> diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc >> index b7cdad517b3..b519712d76e 100644 >> --- a/gcc/gimple-ssa-warn-access.cc >> +++ b/gcc/gimple-ssa-warn-access.cc >> @@ -47,7 +47,7 @@ >> #include "tree-object-size.h" >> #include "tree-ssa-strlen.h" >> #include "calls.h" >> -#include "cfgloop.h" >> +#include "cfganal.h" >> #include "intl.h" >> #include "gimple-range.h" >> #include "stringpool.h" >> @@ -4710,6 +4710,9 @@ pass_waccess::execute (function *fun) >> calculate_dominance_info (CDI_DOMINATORS); >> calculate_dominance_info (CDI_POST_DOMINATORS); >> >> + /* Set or clear EDGE_DFS_BACK bits on back edges. */ >> + mark_dfs_back_edges (fun); >> + >> /* Create a new ranger instance and associate it with FUN. */ >> m_ptr_qry.rvals = enable_ranger (fun); >> m_func = fun; > > Jakub >