From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id DFC513858D28 for ; Wed, 17 Nov 2021 17:25:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DFC513858D28 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-508-MgsjciGmObGA1GqUPoi3PA-1; Wed, 17 Nov 2021 12:25:21 -0500 X-MC-Unique: MgsjciGmObGA1GqUPoi3PA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F0DDE102CB73; Wed, 17 Nov 2021 17:25:19 +0000 (UTC) Received: from localhost (unknown [10.33.36.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0EDE60657; Wed, 17 Nov 2021 17:25:19 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix std::type_info::before for ARM [PR103240] Date: Wed, 17 Nov 2021 17:25:18 +0000 Message-Id: <20211117172518.4166459-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, URI_HEX autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Nov 2021 17:25:25 -0000 Tested powerpc64le-linux, and briefly checkd on armv7hl-linux-gnueabi, pushed to trunk. The r179236 fix for std::type_info::operator== should also have been applied to std::type_info::before. Otherwise two distinct types can compare equivalent due to using a string comparison, when they should do a pointer comparison. libstdc++-v3/ChangeLog: PR libstdc++/103240 * libsupc++/tinfo2.cc (type_info::before): Use unadjusted name to check for the '*' prefix. * testsuite/util/testsuite_shared.cc: Add type_info object for use in new test. * testsuite/18_support/type_info/103240.cc: New test. --- libstdc++-v3/libsupc++/tinfo2.cc | 5 ++- .../testsuite/18_support/type_info/103240.cc | 36 +++++++++++++++++++ .../testsuite/util/testsuite_shared.cc | 12 +++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/18_support/type_info/103240.cc diff --git a/libstdc++-v3/libsupc++/tinfo2.cc b/libstdc++-v3/libsupc++/tinfo2.cc index b587cfd037b..d02021fe538 100644 --- a/libstdc++-v3/libsupc++/tinfo2.cc +++ b/libstdc++-v3/libsupc++/tinfo2.cc @@ -36,7 +36,10 @@ type_info::before (const type_info &arg) const _GLIBCXX_NOEXCEPT #if __GXX_MERGED_TYPEINFO_NAMES return name () < arg.name (); #else - return (name ()[0] == '*') ? name () < arg.name () + /* The name() method will strip any leading '*' prefix. Therefore + take care to look at __name rather than name() when looking for + the "pointer" prefix. */ + return (__name[0] == '*') ? name () < arg.name () : __builtin_strcmp (name (), arg.name ()) < 0; #endif } diff --git a/libstdc++-v3/testsuite/18_support/type_info/103240.cc b/libstdc++-v3/testsuite/18_support/type_info/103240.cc new file mode 100644 index 00000000000..3d5968ac25c --- /dev/null +++ b/libstdc++-v3/testsuite/18_support/type_info/103240.cc @@ -0,0 +1,36 @@ +// { dg-do run } +// { dg-require-sharedlib "" } +// { dg-options "./testsuite_shared.so" } + +#include +#include + +namespace __gnu_test +{ +namespace +{ + struct S { }; + struct T { }; +} + +// Defined in testsuite_shared.so, referring to private type in that library +// with the same mangled name as __gnu_test::::S defined here. +extern const std::type_info& pr103240_private_S; +} + +const std::type_info& private_S = __gnu_test::pr103240_private_S; +const std::type_info& local_S = typeid(__gnu_test::S); +const std::type_info& local_T = typeid(__gnu_test::T); + +int main() +{ + VERIFY( local_S == local_S ); + VERIFY( ! local_S.before(local_S) ); + + VERIFY( local_S != local_T ); + VERIFY( local_S.before(local_T) || local_T.before(local_S) ); + + VERIFY( local_S != private_S ); + // PR libstdc++/103240 + VERIFY( local_S.before(private_S) || private_S.before(local_S) ); +} diff --git a/libstdc++-v3/testsuite/util/testsuite_shared.cc b/libstdc++-v3/testsuite/util/testsuite_shared.cc index c4a7ed4abe5..8c10534c511 100644 --- a/libstdc++-v3/testsuite/util/testsuite_shared.cc +++ b/libstdc++-v3/testsuite/util/testsuite_shared.cc @@ -23,6 +23,9 @@ #include #include #include +#if __cpp_rtti +# include +#endif namespace __gnu_test { @@ -130,4 +133,13 @@ try_function_random_fail() } #endif +#if __cpp_rtti +// PR libstdc++/103240 +namespace +{ + struct S { }; +} +const std::type_info& pr103240_private_S = typeid(S); +#endif + } // end namepace __gnu_test -- 2.31.1