From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6EDEA3858D20; Fri, 28 Oct 2022 20:05:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6EDEA3858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666987558; bh=SL9ItsLEBq2eGaKH+JCcorkPn9bIAjMCyW0sPuIHKFw=; h=From:To:Subject:Date:From; b=vC0y1XuU/9DvqHpI5d22owd9GDe3qxSAKLGFwNW4Pf0LExdCKcEtol9c8c/hGsoAo GBwFvJHp8FX31x8gyqE0ImAICgvx9ElLM3vG4Hak9orloLXRjx46asRzsx59ttdQp3 +RMpQRKoXm8eqxQ50Lr+Do+n8fMHotwIJzQ0HZDc= From: "kim.walisch at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107452] New: Failed to catch C++ exception thrown from multiarch-function (x64 CPUs) Date: Fri, 28 Oct 2022 20:05:57 +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: 11.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kim.walisch at gmail dot com 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=3D107452 Bug ID: 107452 Summary: Failed to catch C++ exception thrown from multiarch-function (x64 CPUs) Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kim.walisch at gmail dot com Target Milestone: --- Hi, Tested using: GCC 11.2.0, Ubuntu 22.10 x64 Tested using: GCC 9.4.0, Ubuntu 18.04 x64 I am using the GCC multiarch feature (also known as function multiversionin= g: https://gcc.gnu.org/onlinedocs/gcc/Function-Multiversioning.html) in my primesieve C++ project to take advantage of the latest supported CPU instruction set e.g. AVX, AVX2, AVX512 (on x64 CPUs). Today I found out that if I throw a C++ exception from a multiarch-function= and I try to catch that exception outside of the originating multiarch-function= but within the same translation unit, then catching the exception fails and my program simply aborts. My exception is thrown from here: https://github.com/kimwalisch/primesieve/blob/776c102f92905401613a83508d607= 44d41df7c73/src/PrimeGenerator.cpp#L332 It should be caught here: https://github.com/kimwalisch/primesieve/blob/776c102f92905401613a83508d607= 44d41df7c73/src/iterator-c.cpp#L151 My bug can be reproduced using these steps: git clone https://github.com/kimwalisch/primesieve.git cd primesieve && mkdir build && cd build git checkout 776c102f92905401613a83508d60744d41df7c73 CXXFLAGS=3D"-O2 -Wall -Wextra -pedantic" cmake .. -DBUILD_TESTS=3DON -DCMAKE_BUILD_TYPE=3DDebug -DWITH_MULTIARCH=3DON && make -j8 test/next_prime2 The test/next_prime2 will fail with the following error message: terminate called after throwing an instance of 'primesieve::primesieve_erro= r' what(): cannot generate primes > 2^64 Aborted If I recompile without function multiversioning (-DWITH_MULTIARCH=3DOFF) th= e same exception is caught successfully: rm -rf * CXXFLAGS=3D"-O2 -Wall -Wextra -pedantic" cmake .. -DBUILD_TESTS=3DON -DCMAKE_BUILD_TYPE=3DDebug -DWITH_MULTIARCH=3DOFF && make -j8 test/next_prime2 The test/next_prime2 completes successfully: ... primesieve_iterator: cannot generate primes > 2^64 next_prime(18446744073709551615) =3D PRIMESIEVE_ERROR: OK primesieve_iterator: cannot generate primes > 2^64 next_prime(18446744073709551615) =3D PRIMESIEVE_ERROR: OK All tests passed successfully! Clang also supports function multiversioning on Linux & x64 CPUs. And with Clang this issue is not present, with Clang catching C++ exceptions thrown = from a multiarch-function works flawlessly (tested using Clang 14.0.0 on Ubuntu 22.10 x64): rm -rf * CXX=3Dclang++ CC=3Dclang CXXFLAGS=3D"-O2 -Wall -Wextra -pedantic" cmake ..= =20 -DBUILD_TESTS=3DON -DCMAKE_BUILD_TYPE=3DDebug -DWITH_MULTIARCH=3DON && make= -j8 test/next_prime2 The test/next_prime2 completes successfully: ... primesieve_iterator: cannot generate primes > 2^64 next_prime(18446744073709551615) =3D PRIMESIEVE_ERROR: OK primesieve_iterator: cannot generate primes > 2^64 next_prime(18446744073709551615) =3D PRIMESIEVE_ERROR: OK All tests passed successfully! Is this a known GCC issue? If needed I could also try to write a minimal te= st that reproduces this issue.=