Skip to content

Commit f829660

Browse files
committed
deps: cherry-pick 8ed65b97 from V8's upstream
Original commit message: Make FieldType::None() non-nullptr value to avoid undefined behaviour When FieldType::None() returns a cast Smi::FromInt(0), which translates as nullptr, the FieldType::IsNone() check becomes equivalent to `this == nullptr` which is not allowed by the standard and therefore optimized away as a false constant by GCC 6. This has lead to crashes when invoking methods on FieldType::None(). Using a different Smi constant for FieldType::None() makes the compiler always include a comparison against that value. The choice of these constants has no effect as they are effectively arbitrary. BUG=#8310 Review-Url: https://codereview.chromium.org/2292953002 Cr-Commit-Position: refs/heads/master@{#39023} Fixes: #8310 PR-URL: #8411 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
1 parent 180867d commit f829660

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

deps/v8/src/field-type.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace internal {
1313

1414
// static
1515
FieldType* FieldType::None() {
16-
return reinterpret_cast<FieldType*>(Smi::FromInt(0));
16+
// Do not Smi::FromInt(0) here or for Any(), as that may translate
17+
// as `nullptr` which is not a valid value for `this`.
18+
return reinterpret_cast<FieldType*>(Smi::FromInt(2));
1719
}
1820

1921
// static

deps/v8/test/cctest/test-field-type-tracking.cc

+11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "src/global-handles.h"
1717
#include "src/ic/stub-cache.h"
1818
#include "src/macro-assembler.h"
19+
#include "src/types.h"
1920

2021
using namespace v8::internal;
2122

@@ -2473,6 +2474,16 @@ TEST(TransitionAccessorConstantToSameAccessorConstant) {
24732474
TestTransitionTo(transition_op, transition_op, checker);
24742475
}
24752476

2477+
TEST(FieldTypeConvertSimple) {
2478+
CcTest::InitializeVM();
2479+
v8::HandleScope scope(CcTest::isolate());
2480+
Isolate* isolate = CcTest::i_isolate();
2481+
2482+
Zone zone(isolate->allocator());
2483+
2484+
CHECK_EQ(FieldType::Any()->Convert(&zone), Type::Any());
2485+
CHECK_EQ(FieldType::None()->Convert(&zone), Type::None());
2486+
}
24762487

24772488
// TODO(ishell): add this test once IS_ACCESSOR_FIELD_SUPPORTED is supported.
24782489
// TEST(TransitionAccessorConstantToAnotherAccessorConstant)

0 commit comments

Comments
 (0)