diff options
Diffstat (limited to 'src/wasm')
-rw-r--r-- | src/wasm/wasm-binary.cpp | 22 | ||||
-rw-r--r-- | src/wasm/wasm-validator.cpp | 7 | ||||
-rw-r--r-- | src/wasm/wasm.cpp | 2 |
3 files changed, 28 insertions, 3 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp index ceb230f73..f98eff670 100644 --- a/src/wasm/wasm-binary.cpp +++ b/src/wasm/wasm-binary.cpp @@ -791,6 +791,11 @@ void WasmBinaryWriter::visitLoad(Load *curr) { default: WASM_UNREACHABLE(); } } else { + if (curr->type == unreachable) { + // don't even emit it; we don't know the right type + o << int8_t(BinaryConsts::Unreachable); + return; + } o << int8_t(BinaryConsts::AtomicPrefix); switch (curr->type) { case i32: { @@ -849,6 +854,11 @@ void WasmBinaryWriter::visitStore(Store *curr) { default: abort(); } } else { + if (curr->type == unreachable) { + // don't even emit it; we don't know the right type + o << int8_t(BinaryConsts::Unreachable); + return; + } o << int8_t(BinaryConsts::AtomicPrefix); switch (curr->valueType) { case i32: { @@ -881,6 +891,12 @@ void WasmBinaryWriter::visitAtomicRMW(AtomicRMW *curr) { recurse(curr->ptr); recurse(curr->value); + if (curr->type == unreachable) { + // don't even emit it; we don't know the right type + o << int8_t(BinaryConsts::Unreachable); + return; + } + o << int8_t(BinaryConsts::AtomicPrefix); #define CASE_FOR_OP(Op) \ @@ -927,6 +943,12 @@ void WasmBinaryWriter::visitAtomicCmpxchg(AtomicCmpxchg *curr) { recurse(curr->expected); recurse(curr->replacement); + if (curr->type == unreachable) { + // don't even emit it; we don't know the right type + o << int8_t(BinaryConsts::Unreachable); + return; + } + o << int8_t(BinaryConsts::AtomicPrefix); switch (curr->type) { case i32: diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp index 6d75296a4..5120eea7a 100644 --- a/src/wasm/wasm-validator.cpp +++ b/src/wasm/wasm-validator.cpp @@ -487,6 +487,7 @@ void FunctionValidator::visitLoad(Load *curr) { validateMemBytes(curr->bytes, curr->type, curr); validateAlignment(curr->align, curr->type, curr->bytes, curr->isAtomic, curr); shouldBeEqualOrFirstIsUnreachable(curr->ptr->type, i32, curr, "load pointer type must be i32"); + if (curr->isAtomic) shouldBeFalse(curr->signed_, curr, "atomic loads must be unsigned"); } void FunctionValidator::visitStore(Store *curr) { @@ -502,7 +503,7 @@ void FunctionValidator::visitAtomicRMW(AtomicRMW* curr) { shouldBeFalse(!getModule()->memory.shared, curr, "Atomic operation with non-shared memory"); validateMemBytes(curr->bytes, curr->type, curr); shouldBeEqualOrFirstIsUnreachable(curr->ptr->type, i32, curr, "AtomicRMW pointer type must be i32"); - shouldBeEqualOrFirstIsUnreachable(curr->value->type, curr->type, curr, "AtomicRMW result type must match operand"); + shouldBeEqualOrFirstIsUnreachable(curr->type, curr->value->type, curr, "AtomicRMW result type must match operand"); shouldBeIntOrUnreachable(curr->type, curr, "Atomic operations are only valid on int types"); } @@ -513,8 +514,8 @@ void FunctionValidator::visitAtomicCmpxchg(AtomicCmpxchg* curr) { if (curr->expected->type != unreachable && curr->replacement->type != unreachable) { shouldBeEqual(curr->expected->type, curr->replacement->type, curr, "cmpxchg operand types must match"); } - shouldBeEqualOrFirstIsUnreachable(curr->expected->type, curr->type, curr, "Cmpxchg result type must match expected"); - shouldBeEqualOrFirstIsUnreachable(curr->replacement->type, curr->type, curr, "Cmpxchg result type must match replacement"); + shouldBeEqualOrFirstIsUnreachable(curr->type, curr->expected->type, curr, "Cmpxchg result type must match expected"); + shouldBeEqualOrFirstIsUnreachable(curr->type, curr->replacement->type, curr, "Cmpxchg result type must match replacement"); shouldBeIntOrUnreachable(curr->expected->type, curr, "Atomic operations are only valid on int types"); } diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp index f4562fe64..6441991c9 100644 --- a/src/wasm/wasm.cpp +++ b/src/wasm/wasm.cpp @@ -390,12 +390,14 @@ void AtomicCmpxchg::finalize() { } void AtomicWait::finalize() { + type = i32; if (ptr->type == unreachable || expected->type == unreachable || timeout->type == unreachable) { type = unreachable; } } void AtomicWake::finalize() { + type = i32; if (ptr->type == unreachable || wakeCount->type == unreachable) { type = unreachable; } |