public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Marek Polacek <polacek@redhat.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Joseph Myers <joseph@codesourcery.com>,
	Richard Biener <rguenther@suse.de>
Subject: Re: [PATCH] c-family: Honor -Wno-init-self for cv-qual vars [PR102633]
Date: Sat, 6 Aug 2022 15:29:05 -0700	[thread overview]
Message-ID: <01d3db21-2cf9-fa81-e1d1-973c479e22a3@redhat.com> (raw)
In-Reply-To: <YuBdKBe6MMaeh54h@redhat.com>

On 7/26/22 14:31, Marek Polacek wrote:
> On Tue, Jul 26, 2022 at 04:24:18PM -0400, Jason Merrill wrote:
>> On 7/26/22 15:03, Marek Polacek wrote:
>>> Since r11-5188-g32934a4f45a721, we drop qualifiers during l-to-r
>>> conversion by creating a NOP_EXPR.  For e.g.
>>>
>>>     const int i = i;
>>>
>>> that means that the DECL_INITIAL is '(int) i' and not 'i' anymore.
>>> Consequently, we don't suppress_warning here:
>>>
>>> 711     case DECL_EXPR:
>>> 715       if (VAR_P (DECL_EXPR_DECL (*expr_p))
>>> 716           && !DECL_EXTERNAL (DECL_EXPR_DECL (*expr_p))
>>> 717           && !TREE_STATIC (DECL_EXPR_DECL (*expr_p))
>>> 718           && (DECL_INITIAL (DECL_EXPR_DECL (*expr_p)) == DECL_EXPR_DECL (*expr_p))
>>> 719           && !warn_init_self)
>>> 720         suppress_warning (DECL_EXPR_DECL (*expr_p), OPT_Winit_self);
>>>
>>> because of the check on line 718 -- (int) i is not i.  So -Wno-init-self
>>> doesn't disable the warning as it's supposed to.
>>>
>>> The following patch fixes it...except it doesn't, for volatile variables
>>> in C++.  The problem is that for
>>>
>>>     volatile int k = k;
>>>
>>> we see that the initializer has TREE_SIDE_EFFECTS, so we perform dynamic
>>> initialization.  So there's no DECL_INITIAL and the suppress_warning
>>> call above is never done.  I suppose we could amend get_no_uninit_warning
>>> to return true for volatile-qualified expressions.  I mean, can we ever
>>> say for a fact that a volatile variable is uninitialized?
>>>
>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>>>
>>> 	PR middle-end/102633
>>>
>>> gcc/c-family/ChangeLog:
>>>
>>> 	* c-gimplify.cc (c_gimplify_expr): Strip NOPs of DECL_INITIAL.
>>
>> I wonder if we want to handle this i = i case earlier, like in finish_decl.
> 
> I could, something like
> 
> @@ -5381,7 +5381,14 @@ finish_decl (tree decl, location_t init_loc, tree init,
>       init = NULL_TREE;
> 
>     if (init)
> -    store_init_value (init_loc, decl, init, origtype);
> +    {
> +      /* In the self-init case, undo the artificial NOP_EXPR we may have
> +    added in convert_lvalue_to_rvalue so that c_gimplify_expr/DECL_EXPR
> +    can perform suppress_warning.  */
> +      if (TREE_CODE (init) == NOP_EXPR && TREE_OPERAND (init, 0) == decl)
> +   init = TREE_OPERAND (init, 0);
> +      store_init_value (init_loc, decl, init, origtype);
> +    }
> 
> but then I'd have to do the same thing in cp_finish_decl because
> decay_conversion also adds a NOP_EXPR for cv-qualified non-class prvalues.
> Is that what we want?  To me that seems less clean than having c_gimplify_expr
> see through NOP_EXPRs.

I was thinking of checking the form of the initializer before 
decay_conversion or anything else messes with it, and calling 
suppress_warning at that point instead of in c_gimplify_expr.

Jason


  reply	other threads:[~2022-08-06 22:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 19:03 Marek Polacek
2022-07-26 20:24 ` Jason Merrill
2022-07-26 21:31   ` Marek Polacek
2022-08-06 22:29     ` Jason Merrill [this message]
2022-08-08 19:06       ` [PATCH v2] " Marek Polacek
2022-08-11  2:05         ` Jason Merrill
2022-08-11 22:30         ` Jason Merrill
2022-07-27  6:41 ` [PATCH] " Richard Biener
2022-07-27 11:37   ` Marek Polacek

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=01d3db21-2cf9-fa81-e1d1-973c479e22a3@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=polacek@redhat.com \
    --cc=rguenther@suse.de \
    /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).