public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114923] New: gcc ignores escaping pointer and applies invalid optimization
@ 2024-05-02 12:51 nfxjfg at googlemail dot com
  2024-05-02 12:52 ` [Bug c/114923] " nfxjfg at googlemail dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: nfxjfg at googlemail dot com @ 2024-05-02 12:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114923
           Summary: gcc ignores escaping pointer and applies invalid
                    optimization
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nfxjfg at googlemail dot com
  Target Milestone: ---

Created attachment 58088
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58088&action=edit
Test case

In this test case, the pointer to a stack-allocated variable is passed to a
volatile variable. That means the pointer definitely escapes. But the compiler
seems to assume that the memory can't change, and returns the initialization
value of the buf variable.

I tried multiple variations of this. Sometimes it generates the correct code,
even though the situation is exactly the same. A call to an external function
often fixes it, but sometimes not (could not produce a reduced test case of the
latter).

This is reduced from some real-word code. The first register access passes the
memory pointer to the hardware, the second access starts the DMA. In the
real-world code there was some more stuff such as waiting for the DMA to
finish, but it doesn't matter for code generation. The code started to fail
after a DMA buffer was moved from a global variable to the stack.

Originally experienced on 12.2.0 / riscv32-unknown-elf, but on godlbolt I can
reproduce it with trunk and some other architectures.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-05-03  0:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 12:51 [Bug c/114923] New: gcc ignores escaping pointer and applies invalid optimization nfxjfg at googlemail dot com
2024-05-02 12:52 ` [Bug c/114923] " nfxjfg at googlemail dot com
2024-05-02 13:24 ` amonakov at gcc dot gnu.org
2024-05-02 13:44 ` nfxjfg at googlemail dot com
2024-05-02 13:56 ` amonakov at gcc dot gnu.org
2024-05-02 19:07 ` [Bug middle-end/114923] " pinskia at gcc dot gnu.org
2024-05-02 19:15 ` pinskia at gcc dot gnu.org
2024-05-02 23:03 ` nfxjfg at googlemail dot com
2024-05-02 23:42 ` pinskia at gcc dot gnu.org
2024-05-03  0:30 ` nfxjfg at googlemail dot com

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).