From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2E6523858289; Tue, 2 May 2023 19:05:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E6523858289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683054316; bh=t9PuX1zQP5p7KA+ojGwuE08Ynh6GmAwEuzGW/rhWpvk=; h=From:To:Subject:Date:From; b=ss+zUguT4LCT7Dv6nMyBh8PPaAObNnTtd3s56pHgilxtE93a4Xb5nr0ehPxo54Mys qNunf4uW2q3TPOLpZR1mdVcdQIWriHDzK5BwFEvXLPd8KRcvHp/ZjNrgge9elaWqGS I/W4MajzP5bQRUckVkkz1mvO/9IY32XMW/4/3Ok8= From: "christian.morales.vega at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109703] New: __builtin_unreachable() reached Date: Tue, 02 May 2023 19:05:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: christian.morales.vega 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=3D109703 Bug ID: 109703 Summary: __builtin_unreachable() reached Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: christian.morales.vega at gmail dot com Target Milestone: --- This (https://github.com/gcc-mirror/gcc/commit/bf78b43873b0b7e8f9a430df38749b8b6= 1f9c9b8#diff-c8a656ef205ec6452ef0bed111a387dc9e7eb2404fb3222a48f9f93b2460bd= 55R278) __builtin_unreachable() is reached using this code -------------------------------------- #include #include int main() { auto lower =3D std::string{"0123456789ABCDEF"}; auto upper =3D boost::algorithm::to_upper_copy(lower); } -------------------------------------- with Boost 1.82. Doing "g++ -O1 -fsanitize=3Dundefined -o main main.cpp && ./main" results in /usr/include/c++/13/bits/basic_string.h:278:29: runtime error: execution reached an unreachable program point This is with gcc-13.1.1-1.fc38.x86_64 from Fedora 38. AFAICT the bug is in libstdc++. During the first iteration, is not until https://github.com/gcc-mirror/gcc/blob/releases/gcc-13.1.0/libstdc%2B%2B-v3= /include/bits/basic_string.tcc#L201 that the data pointer is replaced from the SSO to the heap one; but one line before, in https://github.com/gcc-mirror/gcc/blob/releases/gcc-13.1.0/libstdc%2B%2B-v3= /include/bits/basic_string.tcc#L200 https://github.com/gcc-mirror/gcc/blob/releases/gcc-13.1.0/libstdc%2B%2B-v3= /include/bits/basic_string.h#L293 https://github.com/gcc-mirror/gcc/blob/releases/gcc-13.1.0/libstdc%2B%2B-v3= /include/bits/basic_string.h#L275 , it checks whether it should destroy the data based on whether _M_data() = =3D=3D _M_local_data().=