summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/wasm/wasm-binary.cpp34
-rw-r--r--test/passes/roundtrip_signed.bin.txt26
-rw-r--r--test/passes/roundtrip_signed.passes1
-rw-r--r--test/passes/roundtrip_signed.wasmbin0 -> 151 bytes
4 files changed, 33 insertions, 28 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 18ae724f0..813810016 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -3160,86 +3160,72 @@ void WasmBinaryBuilder::readMemoryAccess(Address& alignment, Address& offset) {
bool WasmBinaryBuilder::maybeVisitLoad(Expression*& out,
uint8_t code,
bool isAtomic) {
- Load* curr;
+ auto* curr = allocator.alloc<Load>();
+ // The signed field does not matter in some cases (where the size of the load
+ // is equal to the size of the type, in which case we do not extend), but give
+ // it a default value nonetheless, to make hashing and other code simpler, so
+ // that they do not need to consider whether the sign matters or not.
+ curr->signed_ = false;
if (!isAtomic) {
switch (code) {
case BinaryConsts::I32LoadMem8S:
- curr = allocator.alloc<Load>();
curr->bytes = 1;
curr->type = Type::i32;
curr->signed_ = true;
break;
case BinaryConsts::I32LoadMem8U:
- curr = allocator.alloc<Load>();
curr->bytes = 1;
curr->type = Type::i32;
- curr->signed_ = false;
break;
case BinaryConsts::I32LoadMem16S:
- curr = allocator.alloc<Load>();
curr->bytes = 2;
curr->type = Type::i32;
curr->signed_ = true;
break;
case BinaryConsts::I32LoadMem16U:
- curr = allocator.alloc<Load>();
curr->bytes = 2;
curr->type = Type::i32;
- curr->signed_ = false;
break;
case BinaryConsts::I32LoadMem:
- curr = allocator.alloc<Load>();
curr->bytes = 4;
curr->type = Type::i32;
break;
case BinaryConsts::I64LoadMem8S:
- curr = allocator.alloc<Load>();
curr->bytes = 1;
curr->type = Type::i64;
curr->signed_ = true;
break;
case BinaryConsts::I64LoadMem8U:
- curr = allocator.alloc<Load>();
curr->bytes = 1;
curr->type = Type::i64;
- curr->signed_ = false;
break;
case BinaryConsts::I64LoadMem16S:
- curr = allocator.alloc<Load>();
curr->bytes = 2;
curr->type = Type::i64;
curr->signed_ = true;
break;
case BinaryConsts::I64LoadMem16U:
- curr = allocator.alloc<Load>();
curr->bytes = 2;
curr->type = Type::i64;
- curr->signed_ = false;
break;
case BinaryConsts::I64LoadMem32S:
- curr = allocator.alloc<Load>();
curr->bytes = 4;
curr->type = Type::i64;
curr->signed_ = true;
break;
case BinaryConsts::I64LoadMem32U:
- curr = allocator.alloc<Load>();
curr->bytes = 4;
curr->type = Type::i64;
- curr->signed_ = false;
break;
case BinaryConsts::I64LoadMem:
- curr = allocator.alloc<Load>();
curr->bytes = 8;
curr->type = Type::i64;
break;
case BinaryConsts::F32LoadMem:
- curr = allocator.alloc<Load>();
curr->bytes = 4;
curr->type = Type::f32;
break;
case BinaryConsts::F64LoadMem:
- curr = allocator.alloc<Load>();
curr->bytes = 8;
curr->type = Type::f64;
break;
@@ -3250,44 +3236,36 @@ bool WasmBinaryBuilder::maybeVisitLoad(Expression*& out,
} else {
switch (code) {
case BinaryConsts::I32AtomicLoad8U:
- curr = allocator.alloc<Load>();
curr->bytes = 1;
curr->type = Type::i32;
break;
case BinaryConsts::I32AtomicLoad16U:
- curr = allocator.alloc<Load>();
curr->bytes = 2;
curr->type = Type::i32;
break;
case BinaryConsts::I32AtomicLoad:
- curr = allocator.alloc<Load>();
curr->bytes = 4;
curr->type = Type::i32;
break;
case BinaryConsts::I64AtomicLoad8U:
- curr = allocator.alloc<Load>();
curr->bytes = 1;
curr->type = Type::i64;
break;
case BinaryConsts::I64AtomicLoad16U:
- curr = allocator.alloc<Load>();
curr->bytes = 2;
curr->type = Type::i64;
break;
case BinaryConsts::I64AtomicLoad32U:
- curr = allocator.alloc<Load>();
curr->bytes = 4;
curr->type = Type::i64;
break;
case BinaryConsts::I64AtomicLoad:
- curr = allocator.alloc<Load>();
curr->bytes = 8;
curr->type = Type::i64;
break;
default:
return false;
}
- curr->signed_ = false;
BYN_TRACE("zz node: AtomicLoad\n");
}
diff --git a/test/passes/roundtrip_signed.bin.txt b/test/passes/roundtrip_signed.bin.txt
new file mode 100644
index 000000000..0406da34a
--- /dev/null
+++ b/test/passes/roundtrip_signed.bin.txt
@@ -0,0 +1,26 @@
+(module
+ (type $none_=>_none (func))
+ (memory $0 16 17)
+ (global $global$0 (mut i32) (i32.const 10))
+ (export "as-br_table-index" (func $0))
+ (export "as-local.set-value" (func $0))
+ (func $0
+ (if
+ (i32.eqz
+ (global.get $global$0)
+ )
+ (return)
+ )
+ (global.set $global$0
+ (i32.sub
+ (global.get $global$0)
+ (i32.const 1)
+ )
+ )
+ (drop
+ (i32.load
+ (i32.const 0)
+ )
+ )
+ )
+)
diff --git a/test/passes/roundtrip_signed.passes b/test/passes/roundtrip_signed.passes
new file mode 100644
index 000000000..2417a0536
--- /dev/null
+++ b/test/passes/roundtrip_signed.passes
@@ -0,0 +1 @@
+remove-unused-module-elements_roundtrip_vacuum_remove-unused-brs_merge-blocks_vacuum_duplicate-function-elimination
diff --git a/test/passes/roundtrip_signed.wasm b/test/passes/roundtrip_signed.wasm
new file mode 100644
index 000000000..46ec0b98c
--- /dev/null
+++ b/test/passes/roundtrip_signed.wasm
Binary files differ