public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "torvalds@linux-foundation.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/94527] RFE: Add an __attribute__ that marks a function as freeing an object
Date: Tue, 07 Apr 2020 23:49:44 +0000	[thread overview]
Message-ID: <bug-94527-4-xjyGduzlix@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-94527-4@http.gcc.gnu.org/bugzilla/>

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

Linus Torvalds <torvalds@linux-foundation.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |torvalds@linux-foundation.o
                   |                            |rg

--- Comment #2 from Linus Torvalds <torvalds@linux-foundation.org> ---
One silly example of potential for dead store elimination would be
kernel/async.c: async_run_entry_fn(), where we have

        /* 2) remove self from the pending queues */
        spin_lock_irqsave(&async_lock, flags);
        list_del_init(&entry->domain_list);
        list_del_init(&entry->global_list);

        /* 3) free the entry */
        kfree(entry);  
        atomic_dec(&entry_count);

and while it's good form to do "list_del_init()" on those fields in entry, the
fact that we then do "kfree(entry)" right afterwards means that the stores that
re-initialize the entry list are dead.

If gcc knew that "kfree(entry)" de-allocates the entry pointer, it could remove
them, the same way gcc already removes dead stores to automatic variables.

But again: warnings about mis-use are likely more important than DSE. We have
had the silly kinds of bugs where we move code around, and some access remains
after a free. We have good tools (both static and dynamic) to find those
after-the-fact, of course, but the compiler warning about stupidity is even
better.

  parent reply	other threads:[~2020-04-07 23:49 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-07 22:44 [Bug tree-optimization/94527] New: " dhowells at redhat dot com
2020-04-07 22:46 ` [Bug tree-optimization/94527] " dhowells at redhat dot com
2020-04-07 22:48 ` law at redhat dot com
2020-04-07 23:49 ` torvalds@linux-foundation.org [this message]
2020-04-08  0:18 ` law at redhat dot com
2020-04-08  0:48 ` torvalds@linux-foundation.org
2020-04-08  6:45 ` [Bug middle-end/94527] " rguenth at gcc dot gnu.org
2020-04-08  7:53 ` redi at gcc dot gnu.org
2020-04-08 16:28 ` msebor at gcc dot gnu.org
2020-04-08 16:44 ` torvalds@linux-foundation.org
2020-10-06 13:04 ` dmalcolm at gcc dot gnu.org
2020-10-27  1:28 ` msebor at gcc dot gnu.org
2020-11-13 21:47 ` msebor at gcc dot gnu.org
2020-11-13 21:57 ` msebor at gcc dot gnu.org
2020-12-03 22:43 ` cvs-commit at gcc dot gnu.org
2020-12-03 22:45 ` msebor 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-94527-4-xjyGduzlix@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).