From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 52452385780A; Mon, 15 Nov 2021 00:20:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 52452385780A From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/103240] New: std::type_info::before gives wrong answer for ARM EABI Date: Mon, 15 Nov 2021 00:20:33 +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: 12.0 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org 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 keywords bug_severity priority component assigned_to reporter target_milestone cf_gcctarget 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Nov 2021 00:20:33 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103240 Bug ID: 103240 Summary: std::type_info::before gives wrong answer for ARM EABI Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: ABI Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- Target: arm*-*-*gnueabi This passes on x86_64 but fails on armv7hl: // f1.C #include namespace { struct S { }; } std::type_info const& t1 =3D typeid(S); // f2.C #include #include extern std::type_info const& t1; namespace { struct S { }; } std::type_info const& t2 =3D typeid(S); int main() { if (t1 =3D=3D t2) { assert( !t1.before(t2) ); assert( !t2.before(t1) ); } else { assert( t1.before(t2) || t2.before(t1) ); } } $ g++ f1.C f2.C $ ./a.out a.out: f2.C:22: int main(): Assertion `t1.before(t2) || t2.before(t1)' fail= ed. qemu: uncaught target signal 6 (Aborted) - core dumped Aborted (core dumped) The problem is in libsupc++/tinfo2.cc bool type_info::before (const type_info &arg) const _GLIBCXX_NOEXCEPT { #if __GXX_MERGED_TYPEINFO_NAMES return name () < arg.name (); #else return (name ()[0] =3D=3D '*') ? name () < arg.name () : __builtin_strcmp (name (), arg.name ()) < 0; #endif } This should have been fixed like operator=3D=3D was in r179236 so that it c= hecks __name[0] not name()[0], otherwise the '*' is skipped and so is never found there. That means we do a strcmp comparison of the mangled names, even when= the '*' says the types must be compared by pointer address. In the testcase the= two structs have the same mangled name, even though they are distinct types (du= e to the unnamed namespaces). The string comparison therefore returns 0, and so neither type is "before" the other, despite being distinct types.=