From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C67D3385840D; Wed, 11 Jan 2023 14:07:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C67D3385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673446030; bh=IxFp0FN8CD/Pn5rNUHItdt2Qd/GzVBTYXjmaVc5taDs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=oZog4m5CudqAm8+yAix02RDVgR0Fm4cghNEK1o/K7oxNcHhpNRn/5YMK9XwyczB5b AnSvdzJVe3jXu3yOg6tF8lqaBMKIJyZEjq3g37d7NtRbkzDxx1y6c+AFLkVORfy4AB 2mThXIJPvxFsy6dK4dFEwxNRNhe5S1iUI5jm2m7s= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/103755] {has,use}_facet() and iostream constructor performance Date: Wed, 11 Jan 2023 14:07:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: FIXED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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=3D103755 --- Comment #16 from Jonathan Wakely --- Unfortunately this change causes a regression for libs that were statically linked to libstdc++.a before the PR 91057 fix. Any object which has the bug= gy std::locale::id::_M_id() code linked into it can get corrupted locale::_Impl::_M_facet arrays, where the facets are at the wrong indices. Before the introduction of __try_use_facet those corrupted _M_facet arrays would result in a failed dynamic_cast and so has_facet would be false and use_facet would throw. With the new code in GCC 13 the static_cast succeeds, but with undefined behaviour. So to avoid a regression from detecting the bug and throwing an exception to crashing with a segfault, I think we need to change __try_use_facet to use dynamic_cast, unfortunately. We will still retain the use of __try_use_facet in std::basic_ios::_M_cache_locale, so we'll still only do three dynamic_casts= not six, so that's still a bit better than it was before.=