Commit 71dbb7fa authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[ptr-compr][ubsan] Use UnalignedSlot only for types which require bigger alignments

Bug: v8:7703
Change-Id: I497fe7e4ba81acbda8564142959f823c5195c5eb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1529008Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60338}
parent a353f453
......@@ -2973,13 +2973,13 @@ class TypedElementsAccessor
DisallowHeapAllocation no_gc;
BackingStore elements = BackingStore::cast(receiver->elements());
ctype* data = static_cast<ctype*>(elements->DataPtr());
#ifdef V8_COMPRESS_POINTERS
// TODO(ishell, v8:8875): See UnalignedSlot<T> for details.
std::fill(UnalignedSlot<ctype>(data + start),
UnalignedSlot<ctype>(data + end), value);
#else
std::fill(data + start, data + end, value);
#endif
if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) {
// TODO(ishell, v8:8875): See UnalignedSlot<T> for details.
std::fill(UnalignedSlot<ctype>(data + start),
UnalignedSlot<ctype>(data + end), value);
} else {
std::fill(data + start, data + end, value);
}
return *array;
}
......@@ -3152,12 +3152,13 @@ class TypedElementsAccessor
if (len == 0) return;
ctype* data = static_cast<ctype*>(elements->DataPtr());
#ifdef V8_COMPRESS_POINTERS
// TODO(ishell, v8:8875): See UnalignedSlot<T> for details.
std::reverse(UnalignedSlot<ctype>(data), UnalignedSlot<ctype>(data + len));
#else
std::reverse(data, data + len);
#endif
if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) {
// TODO(ishell, v8:8875): See UnalignedSlot<T> for details.
std::reverse(UnalignedSlot<ctype>(data),
UnalignedSlot<ctype>(data + len));
} else {
std::reverse(data, data + len);
}
}
static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate,
......
......@@ -125,21 +125,28 @@ RUNTIME_FUNCTION(Runtime_TypedArraySortFast) {
Handle<FixedTypedArrayBase> elements(
FixedTypedArrayBase::cast(array->elements()), isolate);
switch (array->type()) {
#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype) \
case kExternal##Type##Array: { \
ctype* data = static_cast<ctype*>(elements->DataPtr()); \
if (COMPRESS_POINTERS_BOOL && \
kExternal##Type##Array == kExternalFloat64Array) { \
/* TODO(ishell, v8:8875): See UnalignedSlot<T> for details. */ \
std::sort(UnalignedSlot<ctype>(data), \
UnalignedSlot<ctype>(data + length), CompareNum<ctype>); \
} else if (kExternal##Type##Array == kExternalFloat64Array || \
kExternal##Type##Array == kExternalFloat32Array) { \
std::sort(data, data + length, CompareNum<ctype>); \
} else { \
std::sort(data, data + length); \
} \
break; \
#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype) \
case kExternal##Type##Array: { \
ctype* data = static_cast<ctype*>(elements->DataPtr()); \
if (kExternal##Type##Array == kExternalFloat64Array || \
kExternal##Type##Array == kExternalFloat32Array) { \
if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) { \
/* TODO(ishell, v8:8875): See UnalignedSlot<T> for details. */ \
std::sort(UnalignedSlot<ctype>(data), \
UnalignedSlot<ctype>(data + length), CompareNum<ctype>); \
} else { \
std::sort(data, data + length, CompareNum<ctype>); \
} \
} else { \
if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) { \
/* TODO(ishell, v8:8875): See UnalignedSlot<T> for details. */ \
std::sort(UnalignedSlot<ctype>(data), \
UnalignedSlot<ctype>(data + length)); \
} else { \
std::sort(data, data + length); \
} \
} \
break; \
}
TYPED_ARRAYS(TYPED_ARRAY_SORT)
......
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