1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// Test that UBSAN doesn't generate unsigned integer overflow diagnostics 11// from within the hashing internals. 12 13#include <utility> 14#include <cstdint> 15#include <limits> 16#include <string> 17 18#include "test_macros.h" 19 20typedef std::__murmur2_or_cityhash<uint32_t> Hash32; 21typedef std::__murmur2_or_cityhash<uint64_t> Hash64; 22 23void 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 32int main() { 33 const std::string TestCases[] = { 34 "abcdaoeuaoeclaoeoaeuaoeuaousaotehu]+}sthoasuthaoesutahoesutaohesutaoeusaoetuhasoetuhaoseutaoseuthaoesutaohes" 35 "00000000000000000000000000000000000000000000000000000000000000000000000", 36 "1237546895+54+4554985416849484213464984765465464654564565645645646546456546546" 37 }; 38 const size_t NumCases = sizeof(TestCases)/sizeof(TestCases[0]); 39 for (size_t i=0; i < NumCases; ++i) 40 test(TestCases[i].data(), TestCases[i].length()); 41} 42