[turbofan] Remove redundant helper AddIsSafe.
Use the base::bits::SignedAddOverflow32() function instead, which performs an addition and checks for overflow. Bug: v8:5267, v8:7109 Change-Id: I20a5316957a3f72131d318282e8b8e8bb500b4a7 Reviewed-on: https://chromium-review.googlesource.com/797451 Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#51028}
This commit is contained in:
parent
954146a5cf
commit
aa47fd43c4
@ -615,11 +615,6 @@ bool UnionType::Wellformed() {
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Union and intersection
|
// Union and intersection
|
||||||
|
|
||||||
static bool AddIsSafe(int x, int y) {
|
|
||||||
return x >= 0 ? y <= std::numeric_limits<int>::max() - x
|
|
||||||
: y >= std::numeric_limits<int>::min() - x;
|
|
||||||
}
|
|
||||||
|
|
||||||
Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
|
Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
|
||||||
// Fast case: bit sets.
|
// Fast case: bit sets.
|
||||||
if (type1->IsBitset() && type2->IsBitset()) {
|
if (type1->IsBitset() && type2->IsBitset()) {
|
||||||
@ -647,10 +642,9 @@ Type* Type::Intersect(Type* type1, Type* type2, Zone* zone) {
|
|||||||
bitset bits = type1->BitsetGlb() & type2->BitsetGlb();
|
bitset bits = type1->BitsetGlb() & type2->BitsetGlb();
|
||||||
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
|
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
|
||||||
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
|
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
|
||||||
if (!AddIsSafe(size1, size2)) return Any();
|
int size;
|
||||||
int size = size1 + size2;
|
if (base::bits::SignedAddOverflow32(size1, size2, &size)) return Any();
|
||||||
if (!AddIsSafe(size, 2)) return Any();
|
if (base::bits::SignedAddOverflow32(size, 2, &size)) return Any();
|
||||||
size += 2;
|
|
||||||
Type* result_type = UnionType::New(size, zone);
|
Type* result_type = UnionType::New(size, zone);
|
||||||
UnionType* result = result_type->AsUnion();
|
UnionType* result = result_type->AsUnion();
|
||||||
size = 0;
|
size = 0;
|
||||||
@ -849,10 +843,9 @@ Type* Type::Union(Type* type1, Type* type2, Zone* zone) {
|
|||||||
// Slow case: create union.
|
// Slow case: create union.
|
||||||
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
|
int size1 = type1->IsUnion() ? type1->AsUnion()->Length() : 1;
|
||||||
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
|
int size2 = type2->IsUnion() ? type2->AsUnion()->Length() : 1;
|
||||||
if (!AddIsSafe(size1, size2)) return Any();
|
int size;
|
||||||
int size = size1 + size2;
|
if (base::bits::SignedAddOverflow32(size1, size2, &size)) return Any();
|
||||||
if (!AddIsSafe(size, 2)) return Any();
|
if (base::bits::SignedAddOverflow32(size, 2, &size)) return Any();
|
||||||
size += 2;
|
|
||||||
Type* result_type = UnionType::New(size, zone);
|
Type* result_type = UnionType::New(size, zone);
|
||||||
UnionType* result = result_type->AsUnion();
|
UnionType* result = result_type->AsUnion();
|
||||||
size = 0;
|
size = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user