From: Martin Sebor <msebor@gmail.com>
To: Jeff Law <law@redhat.com>,
JiangNing OS <jiangning@os.amperecomputing.com>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] PR91195: fix -Wmaybe-uninitialized warning for conditional store optimization
Date: Wed, 24 Jul 2019 18:09:00 -0000 [thread overview]
Message-ID: <0f07b57e-9def-2758-c58b-ec9200fa4432@gmail.com> (raw)
In-Reply-To: <a8e481fc-3185-aefe-6032-5e63b010cbe3@redhat.com>
On 7/24/19 11:12 AM, Jeff Law wrote:
> On 7/24/19 10:09 AM, Martin Sebor wrote:
>> On 7/24/19 9:25 AM, Jeff Law wrote:
>>> On 7/23/19 10:20 AM, Martin Sebor wrote:
>>>> On 7/22/19 10:26 PM, JiangNing OS wrote:
>>>>> This patch is to fix PR91195. Is it OK for trunk?
>>>>>
>>>>> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>>>>> index 711a31ea597..4db36644160 100644
>>>>> --- a/gcc/ChangeLog
>>>>> +++ b/gcc/ChangeLog
>>>>> @@ -1,3 +1,9 @@
>>>>> +2019-07-22 Jiangning Liu <jiangning.liu@amperecomputing.com>
>>>>> +
>>>>> +Â Â Â PR middle-end/91195
>>>>> +Â Â Â * tree-ssa-phiopt.c (cond_store_replacement): Work around
>>>>> +Â Â Â -Wmaybe-uninitialized warning.
>>>>> +
>>>>>   2019-07-22 Stafford Horne <shorne@gmail.com>
>>>>> Â Â Â Â Â Â Â * config/or1k/or1k.c (or1k_expand_compare): Check for int
>>>>> before
>>>>> diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c
>>>>> index b64bde695f4..7a86007d087 100644
>>>>> --- a/gcc/tree-ssa-phiopt.c
>>>>> +++ b/gcc/tree-ssa-phiopt.c
>>>>> @@ -2240,6 +2240,14 @@ cond_store_replacement (basic_block middle_bb,
>>>>> basic_block join_bb,
>>>>> Â Â Â Â Â Â Â Â tree base = get_base_address (lhs);
>>>>> Â Â Â Â Â Â Â Â if (!auto_var_p (base) || TREE_ADDRESSABLE (base))
>>>>> Â Â Â Â Â Â return false;
>>>>> +
>>>>> +Â Â Â Â Â /* The transformation below will inherently introduce a memory
>>>>> load,
>>>>> +Â Â Â Â for which LHS may not be initialized yet if it is not in NOTRAP,
>>>>> +Â Â Â Â so a -Wmaybe-uninitialized warning message could be triggered.
>>>>> +Â Â Â Â Since it's a bit hard to have a very accurate uninitialization
>>>>> +Â Â Â Â analysis to memory reference, we disable the warning here to
>>>>> avoid
>>>>> +    confusion. */
>>>>> +Â Â Â Â Â TREE_NO_WARNING (lhs) = 1;
>>>>
>>>> The no-warning bit is sometimes (typically?) set by the middle-end
>>>> after a warning has been issued, to avoid triggering other warnings
>>>> down the line for an already diagnosed expression. Unless it's
>>>> done just for the purposes of a single pass and the bit is cleared
>>>> afterwards, using it to avoid potential false positives doesn't
>>>> seem like a robust solution. It will mask warnings for constructs
>>>> that have been determined to be invalid.
>>>>
>>>> FWIW, the middle-end is susceptible to quite a few false positives
>>>> that would nice to avoid. We have discussed various approaches to
>>>> the problem but setting the no-warning bit seems like too blunt of
>>>> an instrument.
>>> All true.
>>>
>>> But in the case JiangNing is working with the transformation inherently
>>> can introduce an uninitialized read. It seems reasonable to mark those
>>> loads he generates that don't have a dominating read.
>>>
>>> His code takes something like
>>>
>>> Â Â if (x)
>>> Â Â Â Â *p = <someval>
>>>
>>> And turns it into
>>>
>>> Â Â t1 = *p;
>>> Â Â t2 = x ? <someval> : t1;
>>> Â Â *p = t2;
>>>
>>> In the past we required there be a dominating read from *p (among other
>>> restrictions). That requirement was meant to ensure *p isn't going to
>>> fault. Jiang's work relaxes that requirement somewhat for objects that
>>> we can prove aren't going to fault via other means.
>>>
>>> Can setting TREE_NO_WARNING on the inserted loads inhibit warnings?
>>> Certainly. However, I believe we use it in other places where we know
>>> the code we're emitting is safe, but can cause a warning. I think
>>> Jiang's work falls into that category.
>>>
>>> I do think the bit should only be set if we don't have a dominating load
>>> to minimize cases where we might inhibit a valid warning.
>>
>> I was thinking of a few cases where setting the no-warning bit might
>> interfere with detecting bugs unrelated to uninitialized reads:
>>
>> Â 1) -Warray-bounds in gimple-ssa-warn-restrict and tree-vrp
>> Â 2) -Wstringop-overflow in tree-ssa-strlen (other than for calls
>> Â Â Â Â to built-ins)
>>
>> I couldn't come up with a test case that shows how it might happen
>> with this patch but I didn't spend too much time on it.
> I bet we could find one and it's more likely to show up on aarch64 than
> x86 due to costing issues. Either way we're making a bit of a judgment
> call -- an extra false positive here due to a load the compiler inserted
> on a path that didn't have one before, or potentially missing a warning
> on that load because of the TREE_NO_WARNING.
>
> I believe the false positive here is worse than the potential missed
> warning.
>
>
>>
>> There are a number of existing instances of setting TREE_NO_WARNING
>> to suppress -Wuninitialized, and some are the cause of known problems.
>> Bugs 51545, 58950, 74762, 74765 or 89697 are examples. They all boil
>> down to the fact that there's just one bit for all warnings. Jakub
>> mentioned adding a hash-map for this. That seems like a simple and
>> good solution.
> I'm not sure how that really helps here. We marking the MEM on the LHS
> and that's not a shared object. I don't see how it's going to be
> significantly different using a hash map vs the bit in this circumstance.
I don't know what Jakub had in mind but the mapping I envision is
one like hash_map<tree, bitmap> that would make it possible to set
a bit for each distinct warning for every tree node. It would let
us set a bit for -Wuninitialized while leaving the bit for
-Warray-bounds (and all other warnings) clear.
>
> If the bit were on an SSA_NAME, or a _DECL node, then the flag bit is
> shared and would be a much larger concern.
For shared objects the mapping would have to be more involved but
I haven't thought about it in any detail to have an idea what it
might look like.
Anyway, if/when someone does come up with a solution for this we
will have to go through all the places where the no-warning bit
is set and replace them with whatever replacement we come up with.
One instance more or less won't make a difference. I just wanted
to point out that setting the bit is not a robust solution.
Martin
next prev parent reply other threads:[~2019-07-24 18:07 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-23 5:52 JiangNing OS
2019-07-23 16:31 ` Martin Sebor
2019-07-24 15:28 ` Jeff Law
2019-07-24 17:00 ` Martin Sebor
2019-07-24 17:23 ` Jeff Law
2019-07-24 18:09 ` Martin Sebor [this message]
2019-07-25 6:27 ` JiangNing OS
2019-07-25 19:09 ` Martin Sebor
2019-07-26 5:07 ` Jeff Law
2019-07-29 16:10 ` Jakub Jelinek
2019-07-30 8:35 ` Richard Biener
2019-07-30 8:36 ` Jakub Jelinek
2019-07-30 8:49 ` Richard Biener
2019-07-30 14:51 ` Martin Sebor
2019-08-07 22:17 ` Jeff Law
2019-09-03 20:22 ` Jeff Law
2019-07-24 16:00 ` Jeff Law
2019-07-29 16:03 ` Jakub Jelinek
2019-09-03 20:27 ` Jeff Law
2019-11-20 0:14 ` Jakub Jelinek
2019-11-20 2:33 ` Jeff Law
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=0f07b57e-9def-2758-c58b-ec9200fa4432@gmail.com \
--to=msebor@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jiangning@os.amperecomputing.com \
--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).