From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 257B63853832; Fri, 21 Oct 2022 13:28:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 257B63853832 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666358910; bh=aQHKwLGRzW2tu5yuY6Iw+6TaNxtgHDrPU1lRkanVDDE=; h=From:To:Subject:Date:From; b=APIptUGHH509GSs8nzaHY8PBHYk9goYZXMPnuOlPiHPy2m/GwsT1H+yF83cpgqoCC riX8sLtFFOdacp9f8nC+fmhVRT4eeVpkeLLXj4hUFfWVLws4h9jm4eilfnnJxcIyvX AJ3LoWQ7Fagk4lXs/y37mlHbwN0Co5vgPdB6tGo4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] libstdc++: std::hash<{unsigned} __intcap> enablement X-Act-Checkin: gcc X-Git-Author: Victor Do Nascimento X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 678c354afea2cd894d2857afd7df366db4dae703 X-Git-Newrev: c4e36618f181789f0b737631bf3c28726c2a1296 Message-Id: <20221021132830.257B63853832@sourceware.org> Date: Fri, 21 Oct 2022 13:28:30 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c4e36618f181789f0b737631bf3c28726c2a1296 commit c4e36618f181789f0b737631bf3c28726c2a1296 Author: Victor Do Nascimento Date: Fri Oct 21 14:27:23 2022 +0100 libstdc++: std::hash<{unsigned} __intcap> enablement Add explicit specializations of the hash class template for the signed and unsigned variants of the CHERI __intcap type via the _Cxx_hashtable_define_trivial_hash function macro. libstdc++-v3/ChangeLog: * include/bits/functional_hash.h (hash): Define overload for __intptr. * testsuite/20_util/hash/cheri_types.cc: New. Diff: --- libstdc++-v3/include/bits/functional_hash.h | 8 ++++ libstdc++-v3/testsuite/20_util/hash/cheri_types.cc | 48 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/libstdc++-v3/include/bits/functional_hash.h b/libstdc++-v3/include/bits/functional_hash.h index 6ca79154fe0..2381fe80a90 100644 --- a/libstdc++-v3/include/bits/functional_hash.h +++ b/libstdc++-v3/include/bits/functional_hash.h @@ -158,6 +158,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Explicit specialization for long long. _Cxx_hashtable_define_trivial_hash(long long) +#ifdef __CHERI__ + /// Explicit specialization for __intcap. + _Cxx_hashtable_define_trivial_hash(__intcap) + + /// Explicit specialization for unsigned __intcap. + _Cxx_hashtable_define_trivial_hash(unsigned __intcap) +#endif + /// Explicit specialization for unsigned short. _Cxx_hashtable_define_trivial_hash(unsigned short) diff --git a/libstdc++-v3/testsuite/20_util/hash/cheri_types.cc b/libstdc++-v3/testsuite/20_util/hash/cheri_types.cc new file mode 100644 index 00000000000..5959a3ac537 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/hash/cheri_types.cc @@ -0,0 +1,48 @@ +// { dg-do run { target c++11 } } +// +// Copyright (C) 2007-2022 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include + +template +void +do_test () +{ + using std::size_t; + + std::hash h; + size_t r = h(v); + + VERIFY( static_cast(v) == r ); +} + +int +main () +{ + constexpr intptr_t smax = LONG_MAX; + constexpr intptr_t smin = LONG_MIN; + constexpr uintptr_t umax = ULONG_MAX; + + do_test(); + do_test(); + do_test(); + + return 0; +}