1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 // Test that UBSAN doesn't generate unsigned integer overflow diagnostics
10 // from within the hashing internals.
11
12 #include <cstdint>
13 #include <functional>
14 #include <limits>
15 #include <string>
16 #include <utility>
17
18 #include "test_macros.h"
19
20 typedef std::__murmur2_or_cityhash<std::uint32_t> Hash32;
21 typedef std::__murmur2_or_cityhash<std::uint64_t> Hash64;
22
test(const void * key,int len)23 void test(const void* key, int len) {
24 for (int i=1; i <= len; ++i) {
25 Hash32 h1;
26 Hash64 h2;
27 DoNotOptimize(h1(key, i));
28 DoNotOptimize(h2(key, i));
29 }
30 }
31
main(int,char **)32 int main(int, char**) {
33 const std::string TestCases[] = {
34 "abcdaoeuaoeclaoeoaeuaoeuaousaotehu]+}sthoasuthaoesutahoesutaohesutaoeusaoetuhasoetuhaoseutaoseuthaoesutaohes",
35 "00000000000000000000000000000000000000000000000000000000000000000000000",
36 "1237546895+54+4554985416849484213464984765465464654564565645645646546456546546"
37 };
38 const std::size_t NumCases = sizeof(TestCases)/sizeof(TestCases[0]);
39 for (std::size_t i=0; i < NumCases; ++i)
40 test(TestCases[i].data(), TestCases[i].length());
41
42 return 0;
43 }
44