public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] libstdc++: std::hash<{unsigned} __intcap> enablement
@ 2022-10-21 13:28 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-10-21 13:28 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:c4e36618f181789f0b737631bf3c28726c2a1296

commit c4e36618f181789f0b737631bf3c28726c2a1296
Author: Victor Do Nascimento <Victor.DoNascimento@arm.com>
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
+// <http://www.gnu.org/licenses/>.
+
+#include <functional>
+#include <climits>
+#include <testsuite_hooks.h>
+
+template<typename T, T v>
+void
+do_test ()
+{
+  using std::size_t;
+
+  std::hash<T> h;
+  size_t r = h(v);
+
+  VERIFY( static_cast<size_t>(v) == r );
+}
+
+int
+main ()
+{
+  constexpr intptr_t smax = LONG_MAX;
+  constexpr intptr_t smin = LONG_MIN;
+  constexpr uintptr_t umax = ULONG_MAX;
+
+  do_test<intptr_t, smin>();
+  do_test<intptr_t, smax>();
+  do_test<uintptr_t, umax>();
+
+  return 0;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-10-21 13:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-21 13:28 [gcc(refs/vendors/ARM/heads/morello)] libstdc++: std::hash<{unsigned} __intcap> enablement Matthew Malcomson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).