Blame SOURCES/gcc8-pr89629.patch

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