ubsan: d-demangle.c:214 signed integer overflow
[official-gcc.git] / libsanitizer / sanitizer_common / sanitizer_hash.h
blob3d97dcc5d2802cc3e2283d4d436c2a117b85fcbf
1 //===-- sanitizer_common.h --------------------------------------*- C++ -*-===//
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 // This file implements a simple hash function.
10 //===----------------------------------------------------------------------===//
12 #ifndef SANITIZER_HASH_H
13 #define SANITIZER_HASH_H
15 #include "sanitizer_internal_defs.h"
17 namespace __sanitizer {
18 class MurMur2HashBuilder {
19 static const u32 m = 0x5bd1e995;
20 static const u32 seed = 0x9747b28c;
21 static const u32 r = 24;
22 u32 h;
24 public:
25 explicit MurMur2HashBuilder(u32 init = 0) { h = seed ^ init; }
26 void add(u32 k) {
27 k *= m;
28 k ^= k >> r;
29 k *= m;
30 h *= m;
31 h ^= k;
33 u32 get() {
34 u32 x = h;
35 x ^= x >> 13;
36 x *= m;
37 x ^= x >> 15;
38 return x;
41 } //namespace __sanitizer
43 #endif // SANITIZER_HASH_H