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

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Jakub Jelinek
<[email protected]>:

https://gcc.gnu.org/g:22a1038ed2080e604fbc6499d4e3b8b30c258fa4

commit r16-9476-g22a1038ed2080e604fbc6499d4e3b8b30c258fa4
Author: Jakub Jelinek <[email protected]>
Date:   Fri Jul 31 08:58:27 2026 +0200

    c++: Don't cache calls which rethrow etc. [PR126508]

    The first 3 testcase below are miscompiled, we happily cache
    calls during constant evaluation which don't depend just on their
    arguments, but also on the current exceptions (uncaught or caught).
    If we decide to cache such functions and then try to evaluate them
    with different uncaught/caught exceptions (or none), we can get wrong
    results.
    We already don't cache calls which allocate and don't free all heap
    allocations, or free some heap allocations they haven't allocated,
    or which call (right now any) metafunctions, or have exited through
    exception, or aren't constant.
    This patch just adds the rethrow/__builtin_uncaught_exceptions/
    __builtin_current_exception calls to the set of non-cacheable operations
    (to be precise, e.g. rethrow would be safe to cache if we can prove
    that the current exception was always thrown from within that function,
    ditto __builtin_current_exception, but it is hard to figure out).
    The last testcase attempts to check if we don't need something similar
    also for __builtin_eh_ptr_adjust_ref, but the call to foo for some reason
    isn't cached and so I don't have a proof we need to handle it too.

    2026-07-31  Jakub Jelinek  <[email protected]>

            PR c++/126508
            * constexpr.cc (cxx_eval_cxa_builtin_fn): Avoid caching
            calls which rethrow or call __builtin_uncaught_exceptions
            or __builtin_current_exception.

            * g++.dg/cpp26/constexpr-eh20.C: New test.
            * g++.dg/cpp26/constexpr-eh21.C: New test.
            * g++.dg/cpp26/constexpr-eh22.C: New test.
            * g++.dg/cpp26/constexpr-eh23.C: New test.

    (cherry picked from commit a5e5c22ad4862846ea705d43c640ca18cc9dd78a)

Reply via email to