Blame SOURCES/gcc8-pr89629.patch

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