public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/109123] Bogus warning: pointer used after 'realloc' -Wuse-after-free with -O2
Date: Tue, 14 Mar 2023 12:17:14 +0000	[thread overview]
Message-ID: <bug-109123-4-2RzcX5UqHA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109123-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109123

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
(In reply to Manuel López-Ibáñez from comment #6)
> (In reply to Manuel López-Ibáñez from comment #5)
> > Is this code motion valid? Is there any point in the middle-end that checks
> > the validity of the pointer beyond a free/realloc?
> > 
> > If there is a point where such check happens, perhaps it would be a good
> > place to apply no_warning attribute to the pointer.
> 
> Answering to myself: It seems the dispute is over the meaning of "use".
> According to the middle-end and for the purposes of realloc/free, "use"
> means dereference, while for the warning "use" is any read of the value.

Yes - that's for practicality since for memory operations we do have
dependences on the realloc.

> By only warning for dereferences, the warning may miss some obvious cases
> like:
> 
>         tmp = realloc(v->_begin, sizeof(double) * n);
>         v->_end = v->_begin + old_size;
>         v->_begin = tmp;
> 
> However, given that the assumption of the middle-end has worked for decades,
> and it will be not possible to fix it, warning only for dereferences (or
> moving warning for value-uses to a level not enabled by -Wall) would seem
> more user-friendly.

Warning for "escapes" (the store is an escape point) is also sensible I think.

Warning for other uses is really only sensible before any code motion pass
took place.

Unfortunately the testsuite is full of cases expected to be diagnosed but
are no longer with any change to the operation.

  parent reply	other threads:[~2023-03-14 12:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-14  9:41 [Bug c/109123] New: Bogus warning: pointer used after 'realloc' -Wuse-after-free manu at gcc dot gnu.org
2023-03-14  9:44 ` [Bug c/109123] Bogus warning: pointer used after 'realloc' -Wuse-after-free with -O2 manu at gcc dot gnu.org
2023-03-14  9:48 ` manu at gcc dot gnu.org
2023-03-14  9:55 ` rguenth at gcc dot gnu.org
2023-03-14 10:00 ` manu at gcc dot gnu.org
2023-03-14 10:03 ` manu at gcc dot gnu.org
2023-03-14 10:22 ` manu at gcc dot gnu.org
2023-03-14 12:17 ` rguenth at gcc dot gnu.org [this message]
2023-03-14 12:51 ` manu at gcc dot gnu.org
2023-03-15  8:16 ` rguenth at gcc dot gnu.org
2023-03-16  7:30 ` cvs-commit at gcc dot gnu.org
2023-03-16  7:31 ` [Bug c/109123] [12 Regression] " rguenth at gcc dot gnu.org
2023-05-08 12:26 ` [Bug tree-optimization/109123] " rguenth at gcc dot gnu.org

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=bug-109123-4-2RzcX5UqHA@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).