From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 075CD3858294; Tue, 26 Dec 2023 15:20:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 075CD3858294 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1703604020; bh=coBj5PpM5sTGSmUl7oxyEwZUtBg2kkfjxoK2sqRKtNA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=U8YN6L42U4TgOpOOVT1b2u/7h5rNklyXPO+8N/j2M0c7vb98oQesa8D5h+SwzFu0i WudMwrqKo+mlq3qA636rKLvCQc1yq9e/n87bv1Q3/daGoGzgX5QiNBzR6QMJroHxer RFa47kFbIxutocUZK4pWeg+kRf2/asl2g69nCFVA= From: "andysem at mail dot ru" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/113099] locale without RTTI uses dynamic_cast before gcc 13.2 or has ODR violation since gcc 13.2 Date: Tue, 26 Dec 2023 15:20:19 +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.4.0 X-Bugzilla-Keywords: ABI, documentation X-Bugzilla-Severity: normal X-Bugzilla-Who: andysem at mail dot ru 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: 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=3D113099 --- Comment #13 from andysem at mail dot ru --- (In reply to Jonathan Wakely from comment #12) > (In reply to andysem from comment #11) > > > I'm not sure what you mean by "the compiler is free to generate code = that takes it into account." Takes what into account? What problem does tha= t freedom cause? > >=20 > > I mean the compiler could move (some part of) dynamic_cast to precede t= he > > check for the standard facet. I.e. of something like this: > >=20 > > template< typename _Facet > > > const _Facet* __try_use_facet(locale const& loc) > > { > > const size_t __i =3D _Facet::id._M_id(); > > const locale::facet** __facets =3D __loc._M_impl->_M_facets; > > const _Facet* __dyn_facet =3D __dynamic_cast< const _Facet* > > >(__facets[__i]); > >=20 > > // checks for every standard facet type > > if (__is_same(_Facet, ...)) > > return static_cast(__facets[__i]); > >=20 > > return __dyn_facet; > > } >=20 > But why? Maybe I'm being slow but I still don't understand what problem is > being solved here. >=20 > Also this would defeat the optimization that avoids the unnecessary overh= ead > of dynamic_cast for standard facets. I have seen gcc sometimes reorder code like this (i.e. move code from under= a branch before it), presumably to improve ILP or prefetch data, I'm not sure. Yes, that defeats the branch, if it is used as an optimization, and I had to prevent this by adding compiler fences in those cases. Granted, in my case = it happened with inlined code, but I imagine LTO makes it possible to perform similar code transformations with out-of-line code as well. I'm not saying this is what actually happens. I'm just pointing out that ev= en the code that is apparently unreachable may influence codegen and cause ODR issues. > > AFAIK, the standard or libstdc++ docs do not require RTTI for std::loca= le to > > function. >=20 > The standard requires RTTI, period. Using -fno-rtti is completely > non-standard and so the standard has nothing to say about it. Yes, but the standard is written with implementations in mind.=