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

            Bug ID: 117789
           Summary: __builtin_unreachable() in basic_string [PR
                    libstdc++/109299] may pessimize
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kim at wayoftao dot net
  Target Milestone: ---

After observing a difference in the handling of std::string between different
versions of gcc and clang and seeing others with the similar problems (such as
https://old.reddit.com/r/cpp/comments/ics6dj/regression_in_gccs_memory_allocation_elision/),
I did some investigating and found that the problem is nontrivial but that at
least reverting
https://github.com/gcc-mirror/gcc/commit/bf78b43873b0b7e8f9a430df38749b8b61f9c9b8
from https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109299 leads to better
optimization on 14.2. It is possible to simulate the revert by dirtily
disabling __builtin__unreachable() with a define, e.g.
https://godbolt.org/z/5xz4nxehv.

The call was originally added to solve a problem, but from one of the comments
in 109299 "And the reason I put the hint in _M_is_local() not in the function
giving the warning is that it might help in other functions too.", one can
surmise that it is perhaps possible to move the __builtin_unreachable()
somewhere else to get the best of both worlds.

Reply via email to