From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id B17C13858D1E; Sat, 27 Apr 2024 18:57:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B17C13858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1714244274; bh=O/Vfu9uz6VzJdlSS+TPoRICUxvy+mQSeS5DsmsFjZ7I=; h=From:To:Subject:Date:From; b=QHGj8WkuWhv0AeLsDXxPy/d8jvZXqIUuYxesqa9IAnqDS7EXXWt8l7tV/Vh67pHmo 1YjK6e3RLCr269seI5YSiEi0/nuFjB/2L51jGomqWQYlzxD76SypipO1lK2jOItmNo P2k2eSRh/S19quu6XJyFrWSMrBFK7Y7hLTD9tpiY= From: "arojas at archlinux dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114872] New: Miscompilation with -O2 after commit 049ec9b981d1f4f97736061d5cf7d0ae990b57d7 Date: Sat, 27 Apr 2024 18:57:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: arojas at archlinux dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114872 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 cra= shes 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=3DC gcc -O2 -fPIC -I/usr/lib/python3.12/site-packages/cysignals -I/u= sr/lib/python3.12/site-packages/sage/cpython/ -I/usr/include/python3.12 -c = element.c -o element.o -v -save-temps=20 Using built-in specs. COLLECT_GCC=3Dgcc Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=3Dada,c,c++,d,fortran,go,lto,m2,objc,obj-c++ --enable-bootstrap --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/= lib --mandir=3D/usr/share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://gitlab.archlinux.org/archlinux/packaging/packages/g= cc/-/issues --with-build-config=3Dbootstrap-lto --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-obj= ect --enable-libstdcxx-backtrace --enable-link-serialization=3D1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdc= xx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20231110 (GCC)=20 COLLECT_GCC_OPTIONS=3D'-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=3Dgeneric' '-march=3Dx86-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=3Dgeneric -march=3Dx86-64 -fPIC -O2 -fpch-preprocess -o el= ement.i ignoring nonexistent directory "/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../x86_64-pc-linux-gnu/in= clude" #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=3D'-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=3Dgeneric' '-march=3Dx86-64' /usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/cc1 -fpreprocessed element.i -quiet -dumpbase element.c -dumpbase-ext .c -mtune=3Dgeneric -march=3Dx86-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=3D100 --param ggc-min-heapsize=3D131= 072 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 poi= nter target type [-Wdiscarded-qualifiers] 12020 | __pyx_v_name =3D TNAM_OBJ(__pyx_v_self->value); | ^ COLLECT_GCC_OPTIONS=3D'-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=3Dgeneric' '-march=3Dx86-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=3D/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_6= 4-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/:/usr/lib/gcc/x86_6= 4-pc-linux-gnu/13.2.1/:/usr/lib/gcc/x86_64-pc-linux-gnu/ LIBRARY_PATH=3D/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/li= b/gcc/x86_64-pc-linux-gnu/13.2.1/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS=3D'-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=3Dgeneric' '-march=3Dx86-64' '-dumpdir' 'element.' At runtime, the crash has the following backtrace: #0 __pthread_kill_implementation (threadid=3D, signo=3Dsigno@entry=3D11, no_tid=3Dno_tid@entry=3D0) at pthread_kill.c:44 #1 0x00007aea958ab393 in __pthread_kill_internal (signo=3D11, threadid=3D) at pthread_kill.c:78 #2 0x00007aea9585a6c8 in __GI_raise (sig=3Dsig@entry=3D11) at ../sysdeps/posix/raise.c:26 #3 0x00007aea955be2f9 in sigdie (sig=3Dsig@entry=3D11, s=3Ds@entry=3D0x7ae= a955c6f78 "Unhandled SIGSEGV: A segmentation fault occurred.") at build/src/cysignals/implementation.c:713 #4 0x00007aea955c267d in sigdie_for_sig (inside=3D0, sig=3D11) at build/src/cysignals/implementation.c:256 #5 cysigs_signal_handler (sig=3D11) at build/src/cysignals/implementation.= c:361 #6 #7 0x00007ae9ba6a5d60 in _Py_IsImmortal (op=3D0x0) at /usr/include/python3.12/object.h:243 #8 Py_DECREF (op=3D0x0) at /usr/include/python3.12/object.h:701 #9 Py_XDECREF (op=3D0x0) at /usr/include/python3.12/object.h:799 #10 __pyx_pf_4sage_4libs_3gap_7element_19GapElement_Function_2__call__ (__pyx_v_self=3D__pyx_v_self@entry=3D0x7ae9b3e90a00,=20 __pyx_v_args=3D__pyx_v_args@entry=3D0x7ae9b57a0400) 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=3D0x7ae9b3e90a00, __pyx_args=3D0x7ae9b57a0400,=20 __pyx_kwds=3D) at build/cythonized/sage/libs/gap/element.c:26110 #12 0x00007aea95bc1949 in _PyObject_Call (tstate=3D0x7aea96031788 <_PyRuntime+459656>, callable=3D0x7ae9b3e90a00, args=3D0x7ae9b57a0400,=20 kwargs=3D) at Objects/call.c:367 #13 0x00007aea95a8d591 in PyCFunction_Call (kwargs=3D0x0, args=3D0x7ae9b57a= 0400, callable=3D0x7ae9b3e90a00) 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=