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

            Bug ID: 115944
           Summary: Incorrect code generation with -Og
           Product: gcc
           Version: 14.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blarsen at redhat dot com
  Target Milestone: ---

Created attachment 58671
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58671&action=edit
small cpp code that reproduces the issue

The issue:

The attached code should segfault in a call to MyClass::call, however,
compiling the code with only -Og -g, the program runs without issue. That's
because the call to "intermediate" (which eventually calls the segfaulting
function) is never added to the assembly, the assembly of the main function
just ends up like this:

000000000040112f <main>:
  40112f:       48 83 ec 08             sub    $0x8,%rsp
  401133:       bf 01 00 00 00          mov    $0x1,%edi
  401138:       e8 f3 fe ff ff          call   401030 <_Znwm@plt>
  40113d:       b8 00 00 00 00          mov    $0x0,%eax
  401142:       48 83 c4 08             add    $0x8,%rsp
  401146:       c3                      ret


Interestingly, adding -fPIC to the compilation line generates correct code.

command line:
  g++       -Og -g gcc_reproducer.cpp

GCC information:

  gcc version 14.1.1 20240701 (Red Hat 14.1.1-7) (GCC) 

  Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --enable-libstdcxx-backtrace
--with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu
--enable-plugin --enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-14.1.1-20240701/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none,amdgcn-amdhsa --enable-offload-defaulted
--without-cuda-driver --enable-gnu-indirect-function --enable-cet
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
--with-build-config=bootstrap-lto --enable-link-serialization=1

Reply via email to