Chromium Code Reviews

Unified Diff: src/wasm/ast-decoder.cc

Issue 1581223002: MIPS: Fix unaligned read/write operations in wasm. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebased. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« src/utils.h ('K') | « src/utils.h ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/ast-decoder.cc
diff --git a/src/wasm/ast-decoder.cc b/src/wasm/ast-decoder.cc
index ffb815771a7c5061a94e15b5925d2c3a9810d4e6..ccce0213054e15d91fb3678526b3cc9e5da45d4b 100644
--- a/src/wasm/ast-decoder.cc
+++ b/src/wasm/ast-decoder.cc
@@ -394,8 +394,8 @@ class LR_WasmDecoder : public Decoder {
error("expected #tableswitch <cases> <table>, fell off end");
break;
}
- uint16_t case_count = *reinterpret_cast<const uint16_t*>(pc_ + 1);
- uint16_t table_count = *reinterpret_cast<const uint16_t*>(pc_ + 3);
+ uint16_t case_count = ReadUnalignedUInt16(pc_ + 1);
+ uint16_t table_count = ReadUnalignedUInt16(pc_ + 3);
len = 5 + table_count * 2;
if (table_count == 0) {
@@ -412,8 +412,8 @@ class LR_WasmDecoder : public Decoder {
// Verify table.
for (int i = 0; i < table_count; i++) {
- uint16_t target =
- *reinterpret_cast<const uint16_t*>(pc_ + 5 + i * 2);
+ uint16_t target = ReadUnalignedUInt16(pc_ + 5 + i * 2);
+
if (target >= 0x8000) {
size_t depth = target - 0x8000;
if (depth > blocks_.size()) {
@@ -805,7 +805,7 @@ class LR_WasmDecoder : public Decoder {
break;
}
case kExprTableSwitch: {
- uint16_t table_count = *reinterpret_cast<const uint16_t*>(p->pc() + 3);
+ uint16_t table_count = ReadUnalignedUInt16(p->pc() + 3);
if (table_count == 1) {
// Degenerate switch with only a default target.
if (p->index == 1) {
@@ -830,7 +830,7 @@ class LR_WasmDecoder : public Decoder {
TFNode* sw = BUILD(Switch, table_count, p->last()->node);
// Allocate environments for each case.
- uint16_t case_count = *reinterpret_cast<const uint16_t*>(p->pc() + 1);
+ uint16_t case_count = ReadUnalignedUInt16(p->pc() + 1);
SsaEnv** case_envs = zone_->NewArray<SsaEnv*>(case_count);
for (int i = 0; i < case_count; i++) {
case_envs[i] = UnreachableEnv();
@@ -846,7 +846,7 @@ class LR_WasmDecoder : public Decoder {
const uint16_t* table =
reinterpret_cast<const uint16_t*>(p->pc() + 5);
for (int i = 0; i < table_count; i++) {
- uint16_t target = table[i];
+ uint16_t target = ReadUnalignedUInt16(table + i);
SsaEnv* env = Split(copy);
env->control = (i == table_count - 1) ? BUILD(IfDefault, sw)
: BUILD(IfValue, i, sw);
@@ -1307,7 +1307,7 @@ class LR_WasmDecoder : public Decoder {
error(pc, msg);
return -1;
}
- return *reinterpret_cast<const V*>(pc + 1);
+ return ReadUnalignedValue<V>(pc + 1);
}
int EnvironmentCount() {
@@ -1502,7 +1502,7 @@ int OpcodeLength(const byte* pc) {
return 1 + length;
}
case kExprTableSwitch: {
- uint16_t table_count = *reinterpret_cast<const uint16_t*>(pc + 3);
+ uint16_t table_count = ReadUnalignedUInt16(pc + 3);
return 5 + table_count * 2;
}
« src/utils.h ('K') | « src/utils.h ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine