public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Eric Botcazou <botcazou@adacore.com>
Cc: Martin Sebor <msebor@redhat.com>, GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Do not erase warning data in gimple_set_location
Date: Tue, 14 Jun 2022 15:33:28 +0200	[thread overview]
Message-ID: <CAFiYyc3URV6ubpcq2kKd6kR_piLqoekhSvsj0ENKZxxBfN-B1g@mail.gmail.com> (raw)
In-Reply-To: <2514895.Lt9SDvczpP@fomalhaut>

On Tue, Jun 14, 2022 at 12:49 PM Eric Botcazou <botcazou@adacore.com> wrote:
>
> > Hmm, I think instead of special-casing UNKNOWN_LOCATION
> > what gimple_set_location should probably do is either not copy
> > warnings at all or union them.  Btw, gimple_set_location also
> > removes a previously set BLOCK (but gimple_set_block preserves
> > the location locus and diagnostic override).
> >
> > So I'd be tempted to axe the copy_warning () completely here.
>
> The first thing I tried, but it regressed the original testcase IIRC.
>
> Even my minimal patch manages to break bootstrap on ARM:
>
> buildslave/workspace/tcwg_gnu_1/abe/snapshots/gcc.git~master/libcpp/lex.cc:
> 1523:9: error: pointer used after ‘void operator delete(void*, std::size_t)’
> [-Werror=use-after-free]
> # 00:31:04 make[3]: *** [Makefile:227: lex.o] Error 1
> # 00:31:04 make[2]: *** [Makefile:9527: all-stage3-libcpp] Error 2
> # 00:31:35 make[1]: *** [Makefile:25887: stage3-bubble] Error 2
> # 00:31:35 make: *** [Makefile:1072: all] Error 2
>
>       /* Don't warn for cases like when a cdtor returns 'this' on ARM.  */
>       else if (warning_suppressed_p (var, OPT_Wuse_after_free))
>         return;
>
> because warning-control.cc:copy_warning also clobbers the warning data of the
> destination.  We have in cp/decl.cc:maybe_return_this the lines:
>
>       /* Return the address of the object.  */
>       tree val = DECL_ARGUMENTS (current_function_decl);
>       suppress_warning (val, OPT_Wuse_after_free);
>
> -Wuse-after-free is suppressed for the location of VAL and the TREE_NO_WARNING
> bit set on it.  But other expressions may have the same location as VAL and
> the TREE_NO_WARNING bit _not_ set, so when you call copy_warning (expr, expr)
> (we do that a lot after failed folding) for them, copy_warning erases the
> warning data of the location.
>
> I have installed the obvious fixlet after testing on x86-64/Linux, but the
> decoupling between TREE_NO_WARNING bit and location looks a bit problematic.

Thanks - that makes more sense.

>
>         * warning-control.cc (copy_warning) [generic version]: Do not erase
>         the warning data of the destination location when the no-warning
>         bit is not set on the source.
>         (copy_warning) [tree version]: Return early if TO is equal to FROM.
>         (copy_warning) [gimple version]: Likewise.
> testsuite/
>         * g++.dg/warn/Wuse-after-free5.C: New test.
>
> --
> Eric Botcazou

      reply	other threads:[~2022-06-14 13:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-10 10:57 Eric Botcazou
2022-06-12 15:38 ` Jeff Law
2022-06-13 11:15 ` Richard Biener
2022-06-13 15:39   ` Martin Sebor
2022-06-14 10:49   ` Eric Botcazou
2022-06-14 13:33     ` 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=CAFiYyc3URV6ubpcq2kKd6kR_piLqoekhSvsj0ENKZxxBfN-B1g@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=botcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=msebor@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).