diff options
Diffstat (limited to 'deps/v8/test/cctest/compiler/codegen-tester.cc')
-rw-r--r-- | deps/v8/test/cctest/compiler/codegen-tester.cc | 81 |
1 files changed, 50 insertions, 31 deletions
diff --git a/deps/v8/test/cctest/compiler/codegen-tester.cc b/deps/v8/test/cctest/compiler/codegen-tester.cc index f66385a92e..0aff318211 100644 --- a/deps/v8/test/cctest/compiler/codegen-tester.cc +++ b/deps/v8/test/cctest/compiler/codegen-tester.cc @@ -3,6 +3,8 @@ // found in the LICENSE file. #include "test/cctest/compiler/codegen-tester.h" + +#include "src/base/overflowing-math.h" #include "src/objects-inl.h" #include "test/cctest/cctest.h" #include "test/cctest/compiler/value-helper.h" @@ -381,7 +383,7 @@ void RunSmiConstant(int32_t v) { // TODO(dcarney): on x64 Smis are generated with the SmiConstantRegister #if !V8_TARGET_ARCH_X64 if (Smi::IsValid(v)) { - RawMachineAssemblerTester<Object*> m; + RawMachineAssemblerTester<Object> m; m.Return(m.NumberConstant(v)); CHECK_EQ(Smi::FromInt(v), m.Call()); } @@ -390,14 +392,14 @@ void RunSmiConstant(int32_t v) { void RunNumberConstant(double v) { - RawMachineAssemblerTester<Object*> m; + RawMachineAssemblerTester<Object> m; #if V8_TARGET_ARCH_X64 // TODO(dcarney): on x64 Smis are generated with the SmiConstantRegister Handle<Object> number = m.isolate()->factory()->NewNumber(v); if (number->IsSmi()) return; #endif m.Return(m.NumberConstant(v)); - Object* result = m.Call(); + Object result = m.Call(); m.CheckNumber(v, result); } @@ -419,11 +421,12 @@ TEST(RunInt32Constants) { TEST(RunSmiConstants) { - for (int32_t i = 1; i < Smi::kMaxValue && i != 0; i = i << 1) { + for (int32_t i = 1; i < Smi::kMaxValue && i != 0; + i = base::ShlWithWraparound(i, 1)) { RunSmiConstant(i); - RunSmiConstant(3 * i); - RunSmiConstant(5 * i); - RunSmiConstant(-i); + RunSmiConstant(base::MulWithWraparound(3, i)); + RunSmiConstant(base::MulWithWraparound(5, i)); + RunSmiConstant(base::NegateWithWraparound(i)); RunSmiConstant(i | 1); RunSmiConstant(i | 3); } @@ -444,9 +447,10 @@ TEST(RunNumberConstants) { FOR_INT32_INPUTS(i) { RunNumberConstant(*i); } } - for (int32_t i = 1; i < Smi::kMaxValue && i != 0; i = i << 1) { + for (int32_t i = 1; i < Smi::kMaxValue && i != 0; + i = base::ShlWithWraparound(i, 1)) { RunNumberConstant(i); - RunNumberConstant(-i); + RunNumberConstant(base::NegateWithWraparound(i)); RunNumberConstant(i | 1); RunNumberConstant(i | 3); } @@ -458,24 +462,25 @@ TEST(RunNumberConstants) { TEST(RunEmptyString) { - RawMachineAssemblerTester<Object*> m; + RawMachineAssemblerTester<Object> m; m.Return(m.StringConstant("empty")); m.CheckString("empty", m.Call()); } TEST(RunHeapConstant) { - RawMachineAssemblerTester<Object*> m; + RawMachineAssemblerTester<Object> m; m.Return(m.StringConstant("empty")); m.CheckString("empty", m.Call()); } TEST(RunHeapNumberConstant) { - RawMachineAssemblerTester<HeapObject*> m; + RawMachineAssemblerTester<void*> m; Handle<HeapObject> number = m.isolate()->factory()->NewHeapNumber(100.5); m.Return(m.HeapConstant(number)); - HeapObject* result = m.Call(); + HeapObject result = + HeapObject::cast(Object(reinterpret_cast<Address>(m.Call()))); CHECK_EQ(result, *number); } @@ -575,6 +580,20 @@ TEST(RunBinopTester) { #if V8_TARGET_ARCH_64_BIT // TODO(ahaas): run int64 tests on all platforms when supported. + +namespace { + +int64_t Add4(int64_t a, int64_t b, int64_t c, int64_t d) { + // Operate on uint64_t values to avoid undefined behavior. + return static_cast<int64_t>( + static_cast<uint64_t>(a) + static_cast<uint64_t>(b) + + static_cast<uint64_t>(c) + static_cast<uint64_t>(d)); +} + +int64_t Add3(int64_t a, int64_t b, int64_t c) { return Add4(a, b, c, 0); } + +} // namespace + TEST(RunBufferedRawMachineAssemblerTesterTester) { { BufferedRawMachineAssemblerTester<int64_t> m; @@ -592,8 +611,8 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) { m.Return(m.Int64Add(m.Parameter(0), m.Parameter(1))); FOR_INT64_INPUTS(i) { FOR_INT64_INPUTS(j) { - CHECK_EQ(*i + *j, m.Call(*i, *j)); - CHECK_EQ(*j + *i, m.Call(*j, *i)); + CHECK_EQ(base::AddWithWraparound(*i, *j), m.Call(*i, *j)); + CHECK_EQ(base::AddWithWraparound(*j, *i), m.Call(*j, *i)); } } } @@ -604,9 +623,9 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) { m.Int64Add(m.Int64Add(m.Parameter(0), m.Parameter(1)), m.Parameter(2))); FOR_INT64_INPUTS(i) { FOR_INT64_INPUTS(j) { - CHECK_EQ(*i + *i + *j, m.Call(*i, *i, *j)); - CHECK_EQ(*i + *j + *i, m.Call(*i, *j, *i)); - CHECK_EQ(*j + *i + *i, m.Call(*j, *i, *i)); + CHECK_EQ(Add3(*i, *i, *j), m.Call(*i, *i, *j)); + CHECK_EQ(Add3(*i, *j, *i), m.Call(*i, *j, *i)); + CHECK_EQ(Add3(*j, *i, *i), m.Call(*j, *i, *i)); } } } @@ -619,10 +638,10 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) { m.Parameter(3))); FOR_INT64_INPUTS(i) { FOR_INT64_INPUTS(j) { - CHECK_EQ(*i + *i + *i + *j, m.Call(*i, *i, *i, *j)); - CHECK_EQ(*i + *i + *j + *i, m.Call(*i, *i, *j, *i)); - CHECK_EQ(*i + *j + *i + *i, m.Call(*i, *j, *i, *i)); - CHECK_EQ(*j + *i + *i + *i, m.Call(*j, *i, *i, *i)); + CHECK_EQ(Add4(*i, *i, *i, *j), m.Call(*i, *i, *i, *j)); + CHECK_EQ(Add4(*i, *i, *j, *i), m.Call(*i, *i, *j, *i)); + CHECK_EQ(Add4(*i, *j, *i, *i), m.Call(*i, *j, *i, *i)); + CHECK_EQ(Add4(*j, *i, *i, *i), m.Call(*j, *i, *i, *i)); } } } @@ -658,10 +677,10 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) { FOR_INT64_INPUTS(i) { FOR_INT64_INPUTS(j) { m.Call(*i, *j); - CHECK_EQ(*i + *j, result); + CHECK_EQ(base::AddWithWraparound(*i, *j), result); m.Call(*j, *i); - CHECK_EQ(*j + *i, result); + CHECK_EQ(base::AddWithWraparound(*j, *i), result); } } } @@ -677,13 +696,13 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) { FOR_INT64_INPUTS(i) { FOR_INT64_INPUTS(j) { m.Call(*i, *i, *j); - CHECK_EQ(*i + *i + *j, result); + CHECK_EQ(Add3(*i, *i, *j), result); m.Call(*i, *j, *i); - CHECK_EQ(*i + *j + *i, result); + CHECK_EQ(Add3(*i, *j, *i), result); m.Call(*j, *i, *i); - CHECK_EQ(*j + *i + *i, result); + CHECK_EQ(Add3(*j, *i, *i), result); } } } @@ -702,16 +721,16 @@ TEST(RunBufferedRawMachineAssemblerTesterTester) { FOR_INT64_INPUTS(i) { FOR_INT64_INPUTS(j) { m.Call(*i, *i, *i, *j); - CHECK_EQ(*i + *i + *i + *j, result); + CHECK_EQ(Add4(*i, *i, *i, *j), result); m.Call(*i, *i, *j, *i); - CHECK_EQ(*i + *i + *j + *i, result); + CHECK_EQ(Add4(*i, *i, *j, *i), result); m.Call(*i, *j, *i, *i); - CHECK_EQ(*i + *j + *i + *i, result); + CHECK_EQ(Add4(*i, *j, *i, *i), result); m.Call(*j, *i, *i, *i); - CHECK_EQ(*j + *i + *i + *i, result); + CHECK_EQ(Add4(*j, *i, *i, *i), result); } } } |