public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
@ 2024-06-18 11:55 melodygoad18 at gmail dot com
  2024-06-18 11:59 ` [Bug c/115539] " schwab@linux-m68k.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: melodygoad18 at gmail dot com @ 2024-06-18 11:55 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115539
           Summary: Misoptimization of application at -O2 -g on x86-64
                    causing segfaults on valid memory accesses where it
                    works on both clang and gcc at -g (no -O2)
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: melodygoad18 at gmail dot com
  Target Milestone: ---

Hi. I maintain a program that gets misoptimized at -O2 -g on gcc 14.1.1. This
wasn't happening on GCC 12 or 13 AFAIR, and it also doesn't happen on Windows.
Only on Linux. This also doesn't happen on clang with the same flags or on gcc
with simply -g. The problem is in the fastreadl_fetch function, where it
crashes on a perfectly valid memory access, but only if it's compiled with gcc
14.1.1 with -O2 -g flags on Linux. gdb is able to access the memory when it
crashes too, so it's most likely a compiler bug.

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
@ 2024-06-18 11:59 ` schwab@linux-m68k.org
  2024-06-18 12:08 ` melodygoad18 at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: schwab@linux-m68k.org @ 2024-06-18 11:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andreas Schwab <schwab@linux-m68k.org> ---
Please read https://gcc.gnu.org/bugs/ and follow the instructions.

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
  2024-06-18 11:59 ` [Bug c/115539] " schwab@linux-m68k.org
@ 2024-06-18 12:08 ` melodygoad18 at gmail dot com
  2024-06-18 12:09 ` melodygoad18 at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: melodygoad18 at gmail dot com @ 2024-06-18 12:08 UTC (permalink / raw)
  To: gcc-bugs

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

fuel <melodygoad18 at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |melodygoad18 at gmail dot com

--- Comment #2 from fuel <melodygoad18 at gmail dot com> ---
gcc -v outputs

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.1.1 20240522 (GCC)

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
  2024-06-18 11:59 ` [Bug c/115539] " schwab@linux-m68k.org
  2024-06-18 12:08 ` melodygoad18 at gmail dot com
@ 2024-06-18 12:09 ` melodygoad18 at gmail dot com
  2024-06-18 12:27 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: melodygoad18 at gmail dot com @ 2024-06-18 12:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from fuel <melodygoad18 at gmail dot com> ---
Created attachment 58463
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58463&action=edit
Preprocessed source

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
                   ` (2 preceding siblings ...)
  2024-06-18 12:09 ` melodygoad18 at gmail dot com
@ 2024-06-18 12:27 ` jakub at gcc dot gnu.org
  2024-06-18 12:46 ` sjames at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-06-18 12:27 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Your testcase isn't self-contained, there is no main, so there isn't much we
can do about it, but from the 220 -Wstrict-aliasing warnings I'd say it is very
likely the code violates TBAA just about everywhere.
Try -O2 -fno-strict-aliasing?  If that helps, most likely it is just bogus code
being compiled.

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
                   ` (3 preceding siblings ...)
  2024-06-18 12:27 ` jakub at gcc dot gnu.org
@ 2024-06-18 12:46 ` sjames at gcc dot gnu.org
  2024-06-18 12:47 ` sjames at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-18 12:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Sam James <sjames at gcc dot gnu.org> ---
fastreadl_fetch in particular looks aliasing unsafe, let alone the rest.

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
                   ` (4 preceding siblings ...)
  2024-06-18 12:46 ` sjames at gcc dot gnu.org
@ 2024-06-18 12:47 ` sjames at gcc dot gnu.org
  2024-06-18 12:47 ` sjames at gcc dot gnu.org
  2024-06-18 16:09 ` [Bug middle-end/115539] " pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-18 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Sam James from comment #5)
> fastreadl_fetch in particular looks aliasing unsafe, let alone the rest.

The code looks derived from 86box or similar. They build with
-fno-strict-aliasing:
https://github.com/86Box/86Box/blob/15d2ee28c7d7f4590f1f69c542081cdb78313b91/cmake/flags-gcc.cmake#L18.

You should be building with it too if using code derived from it.

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

* [Bug c/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
                   ` (5 preceding siblings ...)
  2024-06-18 12:47 ` sjames at gcc dot gnu.org
@ 2024-06-18 12:47 ` sjames at gcc dot gnu.org
  2024-06-18 16:09 ` [Bug middle-end/115539] " pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-06-18 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-06-18

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

* [Bug middle-end/115539] Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2)
  2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
                   ` (6 preceding siblings ...)
  2024-06-18 12:47 ` sjames at gcc dot gnu.org
@ 2024-06-18 16:09 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-18 16:09 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |alias

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The places which are just as likely cause strict aliasing issues:
geteaw
geteal
geteaw_mem
geteal_mem

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

end of thread, other threads:[~2024-06-18 16:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-18 11:55 [Bug c/115539] New: Misoptimization of application at -O2 -g on x86-64 causing segfaults on valid memory accesses where it works on both clang and gcc at -g (no -O2) melodygoad18 at gmail dot com
2024-06-18 11:59 ` [Bug c/115539] " schwab@linux-m68k.org
2024-06-18 12:08 ` melodygoad18 at gmail dot com
2024-06-18 12:09 ` melodygoad18 at gmail dot com
2024-06-18 12:27 ` jakub at gcc dot gnu.org
2024-06-18 12:46 ` sjames at gcc dot gnu.org
2024-06-18 12:47 ` sjames at gcc dot gnu.org
2024-06-18 12:47 ` sjames at gcc dot gnu.org
2024-06-18 16:09 ` [Bug middle-end/115539] " pinskia at gcc dot gnu.org

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