Blame SOURCES/gcc8-pr89629.patch

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