public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114872] New: Miscompilation with -O2 after commit 049ec9b981d1f4f97736061d5cf7d0ae990b57d7
@ 2024-04-27 18:57 arojas at archlinux dot org
  2024-04-27 18:59 ` [Bug c/114872] " arojas at archlinux dot org
                   ` (28 more replies)
  0 siblings, 29 replies; 30+ messages in thread
From: arojas at archlinux dot org @ 2024-04-27 18:57 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114872
           Summary: Miscompilation with -O2 after commit
                    049ec9b981d1f4f97736061d5cf7d0ae990b57d7
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: arojas at archlinux dot org
  Target Milestone: ---

Commit 049ec9b981d1f4f97736061d5cf7d0ae990b57d7 is causing some runtime crashes
in sagemath when compiled with -O2 or higher (-O1 is fine)

The specific affected source file is element.c obtained from cythonizing
element.pyx in
https://github.com/sagemath/sage/blob/10.4.beta4/src/sage/libs/gap/element.pyx

Manual compilation command and output is:

> LANG=C gcc -O2 -fPIC -I/usr/lib/python3.12/site-packages/cysignals -I/usr/lib/python3.12/site-packages/sage/cpython/ -I/usr/include/python3.12 -c element.c -o element.o -v -save-temps 
Using built-in specs.
COLLECT_GCC=gcc
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++
--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 13.2.1 20231110 (GCC) 
COLLECT_GCC_OPTIONS='-O2' '-fPIC' '-I'
'/usr/lib/python3.12/site-packages/cysignals' '-I'
'/usr/lib/python3.12/site-packages/sage/cpython/' '-I'
'/usr/include/python3.12' '-c' '-o' 'element.o' '-v' '-save-temps'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 -E -quiet -v -I
/usr/lib/python3.12/site-packages/cysignals -I
/usr/lib/python3.12/site-packages/sage/cpython/ -I /usr/include/python3.12
element.c -mtune=generic -march=x86-64 -fPIC -O2 -fpch-preprocess -o element.i
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../x86_64-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/python3.12/site-packages/cysignals
 /usr/lib/python3.12/site-packages/sage/cpython/
 /usr/include/python3.12
 /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include
 /usr/local/include
 /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-O2' '-fPIC' '-I'
'/usr/lib/python3.12/site-packages/cysignals' '-I'
'/usr/lib/python3.12/site-packages/sage/cpython/' '-I'
'/usr/include/python3.12' '-c' '-o' 'element.o' '-v' '-save-temps'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 -fpreprocessed element.i -quiet
-dumpbase element.c -dumpbase-ext .c -mtune=generic -march=x86-64 -O2 -version
-fPIC -o element.s
GNU C17 (GCC) version 13.2.1 20231110 (x86_64-pc-linux-gnu)
        compiled by GNU C version 13.2.1 20231110, GMP version 6.3.0, MPFR
version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 45f88f2c66186490486270a091963f0f
element.c: In function
'__pyx_f_4sage_4libs_3gap_7element_10GapElement__type_number':
element.c:12020:16: warning: assignment discards 'const' qualifier from pointer
target type [-Wdiscarded-qualifiers]
12020 |   __pyx_v_name = TNAM_OBJ(__pyx_v_self->value);
      |                ^
COLLECT_GCC_OPTIONS='-O2' '-fPIC' '-I'
'/usr/lib/python3.12/site-packages/cysignals' '-I'
'/usr/lib/python3.12/site-packages/sage/cpython/' '-I'
'/usr/include/python3.12' '-c' '-o' 'element.o' '-v' '-save-temps'
'-mtune=generic' '-march=x86-64'
 as -v -I /usr/lib/python3.12/site-packages/cysignals -I
/usr/lib/python3.12/site-packages/sage/cpython/ -I /usr/include/python3.12 --64
-o element.o element.s
GNU assembler version 2.42.0 (x86_64-pc-linux-gnu) using BFD version (GNU
Binutils) 2.42.0
COMPILER_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-O2' '-fPIC' '-I'
'/usr/lib/python3.12/site-packages/cysignals' '-I'
'/usr/lib/python3.12/site-packages/sage/cpython/' '-I'
'/usr/include/python3.12' '-c' '-o' 'element.o' '-v' '-save-temps'
'-mtune=generic' '-march=x86-64' '-dumpdir' 'element.'

At runtime, the crash has the following backtrace:

#0  __pthread_kill_implementation (threadid=<optimized out>,
signo=signo@entry=11, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007aea958ab393 in __pthread_kill_internal (signo=11,
threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007aea9585a6c8 in __GI_raise (sig=sig@entry=11) at
../sysdeps/posix/raise.c:26
#3  0x00007aea955be2f9 in sigdie (sig=sig@entry=11, s=s@entry=0x7aea955c6f78
"Unhandled SIGSEGV: A segmentation fault occurred.")
    at build/src/cysignals/implementation.c:713
#4  0x00007aea955c267d in sigdie_for_sig (inside=0, sig=11) at
build/src/cysignals/implementation.c:256
#5  cysigs_signal_handler (sig=11) at build/src/cysignals/implementation.c:361
#6  <signal handler called>
#7  0x00007ae9ba6a5d60 in _Py_IsImmortal (op=0x0) at
/usr/include/python3.12/object.h:243
#8  Py_DECREF (op=0x0) at /usr/include/python3.12/object.h:701
#9  Py_XDECREF (op=0x0) at /usr/include/python3.12/object.h:799
#10 __pyx_pf_4sage_4libs_3gap_7element_19GapElement_Function_2__call__
(__pyx_v_self=__pyx_v_self@entry=0x7ae9b3e90a00, 
    __pyx_v_args=__pyx_v_args@entry=0x7ae9b57a0400) at
build/cythonized/sage/libs/gap/element.c:26540
#11 0x00007ae9ba6a6bab in
__pyx_pw_4sage_4libs_3gap_7element_19GapElement_Function_3__call__
(__pyx_v_self=0x7ae9b3e90a00, __pyx_args=0x7ae9b57a0400, 
    __pyx_kwds=<optimized out>) at
build/cythonized/sage/libs/gap/element.c:26110
#12 0x00007aea95bc1949 in _PyObject_Call (tstate=0x7aea96031788
<_PyRuntime+459656>, callable=0x7ae9b3e90a00, args=0x7ae9b57a0400, 
    kwargs=<optimized out>) at Objects/call.c:367
#13 0x00007aea95a8d591 in PyCFunction_Call (kwargs=0x0, args=0x7ae9b57a0400,
callable=0x7ae9b3e90a00) at Objects/call.c:387

which suggests that the null pointer check in Py_XDECREF is being optimized
away.

Attached is the produced element.i

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

end of thread, other threads:[~2024-05-08 19:58 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-27 18:57 [Bug c/114872] New: Miscompilation with -O2 after commit 049ec9b981d1f4f97736061d5cf7d0ae990b57d7 arojas at archlinux dot org
2024-04-27 18:59 ` [Bug c/114872] " arojas at archlinux dot org
2024-04-27 19:03 ` pinskia at gcc dot gnu.org
2024-04-27 19:05 ` pinskia at gcc dot gnu.org
2024-04-27 19:06 ` arojas at archlinux dot org
2024-04-27 20:00 ` [Bug tree-optimization/114872] [13/14/15 Regression] Miscompilation with -O2 after commit r13-8037 pinskia at gcc dot gnu.org
2024-04-29 15:53 ` sjames at gcc dot gnu.org
2024-04-29 16:00 ` jakub at gcc dot gnu.org
2024-04-29 20:05 ` arojas at archlinux dot org
2024-05-01  1:00 ` sjames at gcc dot gnu.org
2024-05-01  1:01 ` sjames at gcc dot gnu.org
2024-05-01  1:01 ` sjames at gcc dot gnu.org
2024-05-01  1:03 ` sjames at gcc dot gnu.org
2024-05-03 11:07 ` dima.pasechnik at cs dot ox.ac.uk
2024-05-03 11:26 ` dima.pasechnik at cs dot ox.ac.uk
2024-05-06 13:53 ` slyfox at gcc dot gnu.org
2024-05-06 17:29 ` jakub at gcc dot gnu.org
2024-05-06 17:59 ` jakub at gcc dot gnu.org
2024-05-06 21:41 ` slyfox at gcc dot gnu.org
2024-05-06 22:08 ` slyfox at gcc dot gnu.org
2024-05-06 22:45 ` dima.pasechnik at cs dot ox.ac.uk
2024-05-07 10:45 ` jakub at gcc dot gnu.org
2024-05-07 11:05 ` slyfox at gcc dot gnu.org
2024-05-07 22:13 ` slyfox at gcc dot gnu.org
2024-05-08  8:18 ` slyfox at gcc dot gnu.org
2024-05-08  8:27 ` rguenth at gcc dot gnu.org
2024-05-08 18:10 ` slyfox at gcc dot gnu.org
2024-05-08 19:17 ` dima.pasechnik at cs dot ox.ac.uk
2024-05-08 19:35 ` pinskia at gcc dot gnu.org
2024-05-08 19:58 ` jakub 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).