Commit 25a4f4d9 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

Hash all strings as signed values

Hashing should ignore the signedness of the type, since different
platforms might define standard types like {char} as either signed or
unsigned. This leads to problems if hashes are included in test
expectations, see https://crrev.com/c/1926032 and
https://crbug.com/1025184#c26.

This CL avoid such problems by always treating the input as signed
values. This also reduces binary size, since the instantiations for
int8_t and uint8_t are identical now and are folded together by the
compiler / linker.

R=jkummerow@chromium.org

Bug: chromium:1025184
Change-Id: I3fee4d8662dd1c31cd6483639fe4edd4511662c5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1926769Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65090}
parent dddc6a90
......@@ -7,6 +7,8 @@
#include "src/strings/string-hasher.h"
#include <type_traits>
#include "src/objects/objects.h"
#include "src/objects/string-inl.h"
#include "src/strings/char-predicates-inl.h"
......@@ -47,9 +49,13 @@ uint32_t StringHasher::GetTrivialHash(int length) {
String::kIsNotIntegerIndexMask;
}
template <typename schar>
uint32_t StringHasher::HashSequentialString(const schar* chars, int length,
template <typename char_t>
uint32_t StringHasher::HashSequentialString(const char_t* chars_raw, int length,
uint64_t seed) {
STATIC_ASSERT(std::is_integral<char_t>::value);
STATIC_ASSERT(sizeof(char_t) <= 2);
using schar = typename std::make_signed<char_t>::type;
const schar* chars = reinterpret_cast<const schar*>(chars_raw);
DCHECK_LE(0, length);
DCHECK_IMPLIES(0 < length, chars != nullptr);
if (length >= 1) {
......
......@@ -16,8 +16,8 @@ class Vector;
class V8_EXPORT_PRIVATE StringHasher final {
public:
StringHasher() = delete;
template <typename schar>
static inline uint32_t HashSequentialString(const schar* chars, int length,
template <typename char_t>
static inline uint32_t HashSequentialString(const char_t* chars, int length,
uint64_t seed);
// Calculated hash value for a string consisting of 1 to
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment