public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Matthew Malcomson <matmal01@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ARM/heads/morello)] libstdc++: std::hash<{unsigned} __intcap> enablement
Date: Fri, 21 Oct 2022 13:28:30 +0000 (GMT)	[thread overview]
Message-ID: <20221021132830.257B63853832@sourceware.org> (raw)

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;
+}

                 reply	other threads:[~2022-10-21 13:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221021132830.257B63853832@sourceware.org \
    --to=matmal01@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).