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 ...@@ -2973,13 +2973,13 @@ class TypedElementsAccessor
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
BackingStore elements = BackingStore::cast(receiver->elements()); BackingStore elements = BackingStore::cast(receiver->elements());
ctype* data = static_cast<ctype*>(elements->DataPtr()); ctype* data = static_cast<ctype*>(elements->DataPtr());
#ifdef V8_COMPRESS_POINTERS if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) {
// TODO(ishell, v8:8875): See UnalignedSlot<T> for details. // TODO(ishell, v8:8875): See UnalignedSlot<T> for details.
std::fill(UnalignedSlot<ctype>(data + start), std::fill(UnalignedSlot<ctype>(data + start),
UnalignedSlot<ctype>(data + end), value); UnalignedSlot<ctype>(data + end), value);
#else } else {
std::fill(data + start, data + end, value); std::fill(data + start, data + end, value);
#endif }
return *array; return *array;
} }
...@@ -3152,12 +3152,13 @@ class TypedElementsAccessor ...@@ -3152,12 +3152,13 @@ class TypedElementsAccessor
if (len == 0) return; if (len == 0) return;
ctype* data = static_cast<ctype*>(elements->DataPtr()); ctype* data = static_cast<ctype*>(elements->DataPtr());
#ifdef V8_COMPRESS_POINTERS if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) {
// TODO(ishell, v8:8875): See UnalignedSlot<T> for details. // TODO(ishell, v8:8875): See UnalignedSlot<T> for details.
std::reverse(UnalignedSlot<ctype>(data), UnalignedSlot<ctype>(data + len)); std::reverse(UnalignedSlot<ctype>(data),
#else UnalignedSlot<ctype>(data + len));
std::reverse(data, data + len); } else {
#endif std::reverse(data, data + len);
}
} }
static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate, static Handle<FixedArray> CreateListFromArrayLikeImpl(Isolate* isolate,
......
...@@ -125,21 +125,28 @@ RUNTIME_FUNCTION(Runtime_TypedArraySortFast) { ...@@ -125,21 +125,28 @@ RUNTIME_FUNCTION(Runtime_TypedArraySortFast) {
Handle<FixedTypedArrayBase> elements( Handle<FixedTypedArrayBase> elements(
FixedTypedArrayBase::cast(array->elements()), isolate); FixedTypedArrayBase::cast(array->elements()), isolate);
switch (array->type()) { switch (array->type()) {
#define TYPED_ARRAY_SORT(Type, type, TYPE, ctype) \ #define TYPED_ARRAY_SORT(Type, type, TYPE, ctype) \
case kExternal##Type##Array: { \ case kExternal##Type##Array: { \
ctype* data = static_cast<ctype*>(elements->DataPtr()); \ ctype* data = static_cast<ctype*>(elements->DataPtr()); \
if (COMPRESS_POINTERS_BOOL && \ if (kExternal##Type##Array == kExternalFloat64Array || \
kExternal##Type##Array == kExternalFloat64Array) { \ kExternal##Type##Array == kExternalFloat32Array) { \
/* TODO(ishell, v8:8875): See UnalignedSlot<T> for details. */ \ if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) { \
std::sort(UnalignedSlot<ctype>(data), \ /* TODO(ishell, v8:8875): See UnalignedSlot<T> for details. */ \
UnalignedSlot<ctype>(data + length), CompareNum<ctype>); \ std::sort(UnalignedSlot<ctype>(data), \
} else if (kExternal##Type##Array == kExternalFloat64Array || \ UnalignedSlot<ctype>(data + length), CompareNum<ctype>); \
kExternal##Type##Array == kExternalFloat32Array) { \ } else { \
std::sort(data, data + length, CompareNum<ctype>); \ std::sort(data, data + length, CompareNum<ctype>); \
} else { \ } \
std::sort(data, data + length); \ } else { \
} \ if (COMPRESS_POINTERS_BOOL && alignof(ctype) > kTaggedSize) { \
break; \ /* 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) 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