From: Richard Biener <richard.guenther@gmail.com>
To: Jeff Law <law@redhat.com>
Cc: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [RFA][PATCH][PR middle-end/61118] Improve tree CFG accuracy for setjmp/longjmp
Date: Mon, 05 Mar 2018 14:07:00 -0000 [thread overview]
Message-ID: <CAFiYyc0W29giSeF=ekCDaWg6K1b51Ak_DurhHiNfHuu7yAE0jA@mail.gmail.com> (raw)
In-Reply-To: <4bf9a4f9-2125-dc31-5c61-b4a29315eda6@redhat.com>
On Fri, Mar 2, 2018 at 11:18 PM, Jeff Law <law@redhat.com> wrote:
> On 02/28/2018 03:43 AM, Richard Biener wrote:
> [ More snipping ]
>
>>
>>> It's actually pretty easy to fix the CFG. We just need to recognize
>>> that a "returns twice" function returns not to the call, but to the
>>> point immediately after the call. So if we have a call to a returns
>>> twice function that ends a block with a single successor, when we wire
>>> up the abnormal dispatcher, we target the single successor rather than
>>> the block containing the returns-twice call.
>>
>> Hmm, I think you need to check whether the successor has a single
>> predecessor, not whether we have a single successor (we always have
>> that unless setjmp also throws). If you fix that you keep the CFG
>> "incorrect" if there are multiple predecessors so I think in addition
>> to properly creating the edges you have to work on the BB building
>> part to ensure that there's a single-predecessor block after
>> returns-twice function calls. Note that currently we force returns-twice
>> to be the first (and only) stmt of a block -- your fix would relax this,
>> returns-twice no longer needs to start a new BB.
> So I found the code which makes the setjmp start a new block. But I
> haven't found the code which makes setjmp end a block. I'm going to
> have to throw things into the debugger to find the latter.
stmt_starts_bb_p
>
> We ought to remove the code that makes the setjmp start a new block.
> That's just unnecessary. setjmp certainly needs to end the block though.
yes, after your change, of course. The code in stmt_starts_bb_p
uses ECF_RETURNS_TWICE, so ...
>
>
>
>>
>> - handle_abnormal_edges (dispatcher_bbs, bb, bb_to_omp_idx,
>> - &ab_edge_call, false);
>> + {
>> + bool target_after_setjmp = false;
>> +
>> + /* If the returns twice statement looks like a setjmp
>> + call at the end of a block with a single successor
>> + then we want the edge from the dispatcher to target
>> + that single successor. That more accurately reflects
>> + actual control flow. The more accurate CFG also
>> + results in fewer false positive warnings. */
>> + if (gsi_stmt (gsi_last_nondebug_bb (bb)) == call_stmt
>> + && gimple_call_fndecl (call_stmt)
>> + && setjmp_call_p (gimple_call_fndecl (call_stmt))
>> + && single_succ_p (bb))
>> + target_after_setjmp = true;
>> + handle_abnormal_edges (dispatcher_bbs, bb, bb_to_omp_idx,
>> + &ab_edge_call, false,
>> + target_after_setjmp);
>> + }
>>
>> I don't exactly get the hops you jump through here -- I think it's
>> better to split the returns-twice (always last stmt of a block after
>> the fixing) and the setjmp-receiver (always first stmt of a block) cases.
>> So, remove the handling of returns-twice from the above case and
>> handle returns-twice via
> Just wanted to verify the setjmp was the last statement in the block and
> the block passed control to a single successor. If the setjmp is not
> the last statement, then having the longjmp pass control to the
> successor block potentially skips over statements between the setjmp and
> the end of the block. That obviously would be bad.
>
> As I mentioned before the single_succ_p test was just my paranoia.
>
> Note that GSI can point to a setjmp receiver at this point. We don't
> want to treat that like a setjmp.
True.
>
>>
>> gimple *last = last_stmt (bb);
>> if (last && ...)
>>
>> also handle all returns-twice calls this way, not only setjmp_call_p.
> Note that setjmp_call_p returns true for any returns-twice function. So
> we are handling those.
... that's intended as well I think.
>
> So I think the open issue with this patch is removal of making the
> setjmp start a block and verification that we always have it end the
> block. The latter should allow some simplifications to the code I added
> in make_edges and provide a level of consistency that is desirable.
We've abstracted that bit into GF_CALL_CTRL_ALTERING which we
compute during CFG build and only ever clear afterwards (so an
indirect call to setjmp via a type not having returns_twice will not
end up ending a BB and will not have abnormal edges associated).
So I don't think anything besides fixing CFG build is necessary.
Well - the whole RTL transition business of course.
Richard.
> Jeff
>
prev parent reply other threads:[~2018-03-05 14:07 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-28 0:16 Jeff Law
2018-02-28 10:43 ` Richard Biener
2018-02-28 10:48 ` Richard Biener
2018-02-28 15:46 ` Jeff Law
2018-02-28 17:35 ` Jeff Law
2018-03-01 10:45 ` Richard Biener
2018-03-05 18:30 ` Michael Matz
2018-03-05 19:08 ` Jeff Law
2018-03-05 19:30 ` Michael Matz
2018-03-06 3:41 ` Jeff Law
2018-03-06 8:57 ` Richard Biener
2018-03-07 6:01 ` Jeff Law
2018-03-08 0:04 ` Peter Bergner
2018-03-08 12:54 ` Michael Matz
2018-03-08 13:22 ` Richard Biener
2018-03-08 13:26 ` Richard Biener
2018-03-08 13:28 ` Michael Matz
2018-03-09 19:42 ` Jeff Law
2018-03-09 20:20 ` Richard Biener
2018-03-09 19:45 ` Jeff Law
2018-03-06 14:17 ` Michael Matz
2018-03-06 14:43 ` Richard Biener
2018-03-06 16:31 ` Michael Matz
2018-03-02 22:18 ` Jeff Law
2018-03-02 23:07 ` Jakub Jelinek
2018-03-02 23:17 ` Jeff Law
2018-03-05 14:07 ` Richard Biener [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAFiYyc0W29giSeF=ekCDaWg6K1b51Ak_DurhHiNfHuu7yAE0jA@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=law@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).