Commit 2d75dd9b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[cleanup] [wasm] Fix (D)CHECK macros

Use the (D)CHECK_{EQ,NE,GT,...} macros instead of (D)CHECK with an
embedded comparison. This gives better error messages and also does the
right comparison for signed/unsigned mismatches.

This will allow us to reenable the readability/check cpplint check.

R=ahaas@chromium.org

Bug: v8:6837
Change-Id: Ic8966dfeacf02b2684eeef23fde99ec2be4ed81e
Reviewed-on: https://chromium-review.googlesource.com/671364
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#48080}
parent 447af335
......@@ -1100,8 +1100,8 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(Node* node,
Node* lowerByte;
Node* higherByte;
DCHECK(shiftCount > 0);
DCHECK((shiftCount + 8) % 16 == 0);
DCHECK_LT(0, shiftCount);
DCHECK_EQ(0, (shiftCount + 8) % 16);
if (valueSizeInBits > 32) {
shiftLower = graph()->NewNode(m->Word64Shl(), value,
......@@ -1237,8 +1237,8 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node,
Node* lowerByte;
Node* higherByte;
DCHECK(shiftCount > 0);
DCHECK((shiftCount + 8) % 16 == 0);
DCHECK_LT(0, shiftCount);
DCHECK_EQ(0, (shiftCount + 8) % 16);
if (valueSizeInBits > 32) {
shiftLower = graph()->NewNode(m->Word64Shl(), value,
......
......@@ -94,7 +94,7 @@ Object* ThrowRuntimeError(Isolate* isolate, int message_id, int byte_offset,
Handle<FrameArray> stack_elements(
FrameArray::cast(JSArray::cast(*stack_trace_obj)->elements()));
DCHECK(stack_elements->Code(0)->kind() == AbstractCode::WASM_FUNCTION);
DCHECK(stack_elements->Offset(0)->value() >= 0);
DCHECK_LE(0, stack_elements->Offset(0)->value());
stack_elements->SetOffset(0, Smi::FromInt(-1 - byte_offset));
}
......@@ -268,7 +268,7 @@ RUNTIME_FUNCTION(Runtime_WasmStackGuard) {
}
RUNTIME_FUNCTION(Runtime_WasmCompileLazy) {
DCHECK(args.length() == 0);
DCHECK_EQ(0, args.length());
HandleScope scope(isolate);
return *wasm::CompileLazy(isolate);
......
......@@ -1992,7 +1992,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
}
inline Value* Push(ValueType type) {
DCHECK(type != kWasmStmt);
DCHECK_NE(kWasmStmt, type);
stack_.push_back(Value::New(this->pc_, type));
return &stack_.back();
}
......
......@@ -779,7 +779,7 @@ DecodeResult VerifyWasmCodeWithStats(AccountingAllocator* allocator,
auto size_histogram = is_wasm ? counters->wasm_wasm_function_size_bytes()
: counters->wasm_asm_function_size_bytes();
// TODO(bradnelson): Improve histogram handling of ptrdiff_t.
CHECK((body.end - body.start) >= 0);
CHECK_LE(0, body.end - body.start);
size_histogram->AddSample(static_cast<int>(body.end - body.start));
auto time_counter = is_wasm ? counters->wasm_decode_wasm_function_time()
: counters->wasm_decode_asm_function_time();
......
......@@ -2372,7 +2372,7 @@ class AsyncCompileJob::ExecuteAndFinishCompilationUnits : public CompileStep {
// FinishCompilationUnits task again.
break;
} else {
DCHECK(func_index >= 0);
DCHECK_LE(0, func_index);
job_->code_table_->set(func_index, *result.ToHandleChecked());
--job_->outstanding_units_;
}
......
......@@ -1118,7 +1118,7 @@ class ModuleDecoderImpl : public Decoder {
errorf(pos - 1, "invalid %s limits flags", name);
}
if (flags == 3) {
DCHECK(has_shared_memory != nullptr);
DCHECK_NOT_NULL(has_shared_memory);
*has_shared_memory = true;
} else if (flags == 2) {
errorf(pos - 1,
......
......@@ -334,7 +334,7 @@ void UnpackAndRegisterProtectedInstructions(Isolate* isolate,
const int index = RegisterHandlerData(reinterpret_cast<void*>(base), size,
unpacked.size(), &unpacked[0]);
// TODO(eholk): if index is negative, fail.
DCHECK(index >= 0);
DCHECK_LE(0, index);
code->set_trap_handler_index(Smi::FromInt(index));
}
}
......
......@@ -298,7 +298,7 @@ Handle<JSArrayBuffer> GrowMemoryBuffer(Isolate* isolate,
size_t new_size =
static_cast<size_t>(old_pages + pages) * WasmModule::kPageSize;
if (enable_guard_regions && old_size != 0) {
DCHECK(old_buffer->backing_store() != nullptr);
DCHECK_NOT_NULL(old_buffer->backing_store());
if (new_size > FLAG_wasm_max_mem_pages * WasmModule::kPageSize ||
new_size > kMaxInt) {
return Handle<JSArrayBuffer>::null();
......
......@@ -287,7 +287,7 @@ class WasmSerializationTest {
Handle<Object>(Smi::FromInt(41), current_isolate())};
int32_t result = testing::CallWasmFunctionForTesting(
current_isolate(), instance, &thrower, kFunctionName, 1, params);
CHECK(result == 42);
CHECK_EQ(42, result);
}
Isolate* current_isolate() {
......@@ -452,7 +452,7 @@ TEST(ModuleBuilder) {
size_t third = buffer.size() / 3;
size_t first_mark = third - 2;
size_t second_mark = buffer.size() - 2 - third;
CHECK(0 < first_mark);
CHECK_LT(0, first_mark);
CHECK(first_mark < second_mark);
CHECK(second_mark < buffer.size());
Isolate* i_isolate = CcTest::InitIsolateOnce();
......@@ -482,7 +482,7 @@ TEST(FailingModuleBuilder) {
size_t third = buffer.size() / 3;
size_t first_mark = third - 2;
size_t second_mark = buffer.size() - 2 - third;
CHECK(0 < first_mark);
CHECK_LT(0, first_mark);
CHECK(first_mark < second_mark);
CHECK(second_mark < buffer.size());
Isolate* i_isolate = CcTest::InitIsolateOnce();
......@@ -795,7 +795,7 @@ TEST(Run_WasmModule_GrowMemOobFixedIndex) {
Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(1), isolate)};
int32_t result =
testing::RunWasmModuleForTesting(isolate, instance, 1, params);
CHECK(result == 0xaced);
CHECK_EQ(0xaced, result);
}
Cleanup();
}
......@@ -846,7 +846,7 @@ TEST(Run_WasmModule_GrowMemOobVariableIndex) {
Handle<Object>(Smi::FromInt((20 + i) * kPageSize - 4), isolate)};
int32_t result =
testing::RunWasmModuleForTesting(isolate, instance, 1, params);
CHECK(result == 0xaced);
CHECK_EQ(0xaced, result);
}
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
......
......@@ -425,7 +425,7 @@ void WasmFunctionCompiler::Build(const byte* start, const byte* end) {
// Manually add the deoptimization info that would otherwise be added
// during instantiation. Deopt data holds <WeakCell<wasm_instance>,
// func_index>.
DCHECK(code->deoptimization_data()->length() == 0);
DCHECK_EQ(0, code->deoptimization_data()->length());
Handle<FixedArray> deopt_data =
isolate()->factory()->NewFixedArray(2, TENURED);
Handle<Object> weak_instance =
......
......@@ -101,7 +101,7 @@ class TestingModuleBuilder {
byte AddSignature(FunctionSig* sig) {
test_module_.signatures.push_back(sig);
size_t size = test_module_.signatures.size();
CHECK(size < 127);
CHECK_GT(127, size);
return static_cast<byte>(size - 1);
}
......
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