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

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

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

--- Comment #2 from Linus Torvalds <torva...@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.

Reply via email to