Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 699938 - sys-devel/gcc-9.2.0-r2 g++ segfault compiling invalid OpenMP C++ code with -O2 -fopenmp
Summary: sys-devel/gcc-9.2.0-r2 g++ segfault compiling invalid OpenMP C++ code with -O...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: https://gcc.gnu.org/PR92504
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-12 11:40 UTC by Marc Vinyals
Modified: 2019-12-22 11:30 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
Minimal code that triggers a segfault (gccsegfault.cc,136 bytes, text/x-c++src)
2019-11-12 11:40 UTC, Marc Vinyals
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Vinyals 2019-11-12 11:40:00 UTC
Created attachment 595858 [details]
Minimal code that triggers a segfault

Compiling the attached invalid OpenMP C++ code with g++ -O2 -fopenmp leads to a segmentation fault:

$ g++ -O2 -fopenmp gccsegfault.cc
gccsegfault.cc: In function 'int main()':
gccsegfault.cc:7:3: internal compiler error: Segmentation fault
    7 |   }
      |   ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://bugs.gentoo.org/> for instructions.

Compiling with g++ -fopenmp works as expected, i.e. there is an unreadable wall of text because there are missing parentheses after v.end in the comparison part of the for loop.

I did not try older versions of gcc.

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/9.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /var/tmpnomem/portage/sys-devel/gcc-9.2.0-r2/work/gcc-9.2.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/9.2.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/include/g++-v9 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/9.2.0/python --enable-languages=c,c++,go,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 9.2.0-r2 p3' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --enable-libgomp --disable-libmudflap --disable-libssp --disable-systemtap --enable-vtable-verify --enable-lto --without-isl --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 9.2.0 (Gentoo 9.2.0-r2 p3)
Comment 1 Sergei Trofimovich (RETIRED) gentoo-dev 2019-11-13 21:16:55 UTC
Confirmed. Looking.
Comment 2 Sergei Trofimovich (RETIRED) gentoo-dev 2019-11-13 22:46:45 UTC
Filed upstream bug as: https://gcc.gnu.org/PR92504
Comment 3 Larry the Git Cow gentoo-dev 2019-11-19 22:55:53 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=e9c37fb661aed82754e6fd374457a88d697e3091

commit e9c37fb661aed82754e6fd374457a88d697e3091
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2019-11-19 22:55:04 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2019-11-19 22:55:04 +0000

    9.2.0: backport openmp for loop SIGSEGV fix
    
    Reported-by: Marc Vinyals
    Bug: https://gcc.gnu.org/PR92504
    Bug: https://bugs.gentoo.org/699938
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 9.2.0/gentoo/31_all_openmp-for-SEGV.patch | 62 +++++++++++++++++++++++++++++++
 9.2.0/gentoo/README.history               |  3 ++
 2 files changed, 65 insertions(+)
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2019-11-19 22:58:06 UTC
Queued upstream fix for next 9.2.0 patchset as
    https://gitweb.gentoo.org/proj/gcc-patches.git/plain/9.2.0/gentoo/31_all_openmp-for-SEGV.patch

The patchset should be released in a few weeks. Until now if you want to test a fix you can drop the patch to /etc/portage/patches/sys-devel/gcc:9.2.0/ and rebuild gcc.
Comment 5 Larry the Git Cow gentoo-dev 2019-12-22 11:11:14 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gcc-patches.git/commit/?id=35beff919bc59076c5c1aa549e04d8119c559261

commit 35beff919bc59076c5c1aa549e04d8119c559261
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2019-12-22 11:07:00 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2019-12-22 11:07:00 +0000

    9.2.0: cut 4 patchset
    
    4 new patches:
    - 27_all_sparc-PIC-constant-PR91472.patch: fix PIC register alocation
      (bug detected by gmp test suite)
    - 31_all_openmp-for-SEGV.patch: fix opemnmp for loop condition folding
    - 32_all_sparc-PIC-constant-part2.patch: fix PIC register allocation
      (bug detected by python regressin)
    - 33_all_extend-lifetime.patch: fix lifetime extension on ':?' operator
      (bug detected by firefox LTO build
    
    Bug: https://gcc.gnu.org/PR91472
    Bug: https://bugs.gentoo.org/699938
    Bug: https://gcc.gnu.org/PR92504
    Bug: https://bugs.gentoo.org/697708
    Bug: https://gcc.gnu.org/PR92095
    Bug: https://bugs.gentoo.org/701866
    Bug: https://gcc.gnu.org/PR92831
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 9.2.0/gentoo/README.history | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Comment 6 Larry the Git Cow gentoo-dev 2019-12-22 11:28:40 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=649ef16ea81488d36fae3fa4a8881c9e665d2e7a

commit 649ef16ea81488d36fae3fa4a8881c9e665d2e7a
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2019-12-22 11:24:45 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2019-12-22 11:28:34 +0000

    sys-devel/gcc: 9.2.0: cut 4 patchset
    
    4 new patches:
    - 27_all_sparc-PIC-constant-PR91472.patch: fix PIC register alocation
      (bug detected by gmp test suite)
    - 31_all_openmp-for-SEGV.patch: fix opemnmp for loop condition folding
    - 32_all_sparc-PIC-constant-part2.patch: fix PIC register allocation
      (bug detected by python regressin)
    - 33_all_extend-lifetime.patch: fix lifetime extension on ':?' operator
      (bug detected by firefox LTO build
    
    Bug: https://gcc.gnu.org/PR91472
    Bug: https://bugs.gentoo.org/699938
    Bug: https://gcc.gnu.org/PR92504
    Bug: https://bugs.gentoo.org/697708
    Bug: https://gcc.gnu.org/PR92095
    Bug: https://bugs.gentoo.org/701866
    Bug: https://gcc.gnu.org/PR92831
    Package-Manager: Portage-2.3.82, Repoman-2.3.20
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 sys-devel/gcc/Manifest            |  1 +
 sys-devel/gcc/gcc-9.2.0-r3.ebuild | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
Comment 7 Sergei Trofimovich (RETIRED) gentoo-dev 2019-12-22 11:30:48 UTC
Should be fixed in gcc-9.2.0-r3. Thank you for the perfect report!