4332b90
2019-03-11  Jonathan Wakely  <jwakely@redhat.com>
4332b90
4332b90
	PR libstdc++/89629
4332b90
	* libsupc++/hash_bytes.cc [__SIZEOF_SIZE_T__ == 8] (_Hash_bytes):
4332b90
	Use correct type for len_aligned.
4332b90
	* testsuite/20_util/hash/89629.cc: New test.
4332b90
4332b90
--- libstdc++-v3/libsupc++/hash_bytes.cc	(revision 269583)
4332b90
+++ libstdc++-v3/libsupc++/hash_bytes.cc	(revision 269584)
4332b90
@@ -139,7 +139,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
4332b90
 
4332b90
     // Remove the bytes not divisible by the sizeof(size_t).  This
4332b90
     // allows the main loop to process the data as 64-bit integers.
4332b90
-    const int len_aligned = len & ~0x7;
4332b90
+    const size_t len_aligned = len & ~(size_t)0x7;
4332b90
     const char* const end = buf + len_aligned;
4332b90
     size_t hash = seed ^ (len * mul);
4332b90
     for (const char* p = buf; p != end; p += 8)
4332b90
--- libstdc++-v3/testsuite/20_util/hash/89629.cc	(nonexistent)
4332b90
+++ libstdc++-v3/testsuite/20_util/hash/89629.cc	(revision 269584)
4332b90
@@ -0,0 +1,43 @@
4332b90
+// Copyright (C) 2019 Free Software Foundation, Inc.
4332b90
+//
4332b90
+// This file is part of the GNU ISO C++ Library.  This library is free
4332b90
+// software; you can redistribute it and/or modify it under the
4332b90
+// terms of the GNU General Public License as published by the
4332b90
+// Free Software Foundation; either version 3, or (at your option)
4332b90
+// any later version.
4332b90
+
4332b90
+// This library is distributed in the hope that it will be useful,
4332b90
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
4332b90
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4332b90
+// GNU General Public License for more details.
4332b90
+
4332b90
+// You should have received a copy of the GNU General Public License along
4332b90
+// with this library; see the file COPYING3.  If not see
4332b90
+// <http://www.gnu.org/licenses/>.
4332b90
+
4332b90
+// { dg-do run { target { lp64 || llp64 } } }
4332b90
+// { dg-require-effective-target c++11 }
4332b90
+// { dg-require-effective-target run_expensive_tests }
4332b90
+
4332b90
+#include <functional>
4332b90
+#include <string>
4332b90
+
4332b90
+void
4332b90
+test01()
4332b90
+{
4332b90
+  const std::size_t big = std::size_t(1) << 31;
4332b90
+  std::string s;
4332b90
+  try {
4332b90
+    s.resize(big, 'a');
4332b90
+  } catch (const std::bad_alloc&) {
4332b90
+    return; // try to avoid a FAIL if memory allocation fails
4332b90
+  }
4332b90
+  // PR libstdc++/89629
4332b90
+  (void) std::hash<std::string>{}(s);
4332b90
+}
4332b90
+
4332b90
+int
4332b90
+main()
4332b90
+{
4332b90
+  test01();
4332b90
+}