summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h9
-rw-r--r--test/unit.asm.js4
-rw-r--r--test/unit.wast8
3 files changed, 19 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 394b3de9f..ac9732e68 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -965,11 +965,16 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
ret->type = WasmType::i32;
return ret;
}
- assert(asmType == ASM_DOUBLE);
auto ret = allocator.alloc<Unary>();
ret->op = Neg;
ret->value = process(ast[2]);
- ret->type = WasmType::f64;
+ if (asmType == ASM_DOUBLE) {
+ ret->type = WasmType::f64;
+ } else if (asmType == ASM_FLOAT) {
+ ret->type = WasmType::f32;
+ } else {
+ abort();
+ }
return ret;
} else if (ast[1] == B_NOT) {
// ~, might be ~~ as a coercion or just a not
diff --git a/test/unit.asm.js b/test/unit.asm.js
index 790678f41..0a664ca3f 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -106,6 +106,10 @@ function () {
y = +Math_abs(0.0);
z = Math_fround(Math_abs(Math_fround(0)));
}
+ function neg() {
+ var x = Math_fround(0);
+ x = -x;
+ }
function z() {
}
diff --git a/test/unit.wast b/test/unit.wast
index b8823d34f..dd1f59d2d 100644
--- a/test/unit.wast
+++ b/test/unit.wast
@@ -327,6 +327,14 @@
)
)
)
+ (func $neg
+ (local $x f32)
+ (set_local $x
+ (f32.neg
+ (get_local $x)
+ )
+ )
+ )
(func $z
(nop)
)