Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7b9e68c

Browse files
committed
WASM_X64: Fix floating-point exception (core dumped) error
1 parent f753dcb commit 7b9e68c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libasr/codegen/wasm_to_x64.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,10 @@ class X64Visitor : public WASMDecoder<X64Visitor>,
312312
handleI32Opt([&](){ m_a.asm_mul_r64(X64Reg::rbx);});
313313
}
314314
void visit_I32DivS() {
315-
handleI32Opt([&](){ m_a.asm_div_r64(X64Reg::rbx);});
315+
handleI32Opt([&](){
316+
m_a.asm_mov_r64_imm64(X64Reg::rdx, 0);
317+
m_a.asm_div_r64(X64Reg::rbx);
318+
});
316319
}
317320

318321
void visit_I32And() {
@@ -397,7 +400,9 @@ class X64Visitor : public WASMDecoder<X64Visitor>,
397400
handleI64Opt([&](){ m_a.asm_mul_r64(X64Reg::rbx);});
398401
}
399402
void visit_I64DivS() {
400-
handleI64Opt([&](){ m_a.asm_div_r64(X64Reg::rbx);});
403+
handleI64Opt([&](){
404+
m_a.asm_mov_r64_imm64(X64Reg::rdx, 0);
405+
m_a.asm_div_r64(X64Reg::rbx);});
401406
}
402407

403408
void visit_I64And() {
@@ -415,6 +420,7 @@ class X64Visitor : public WASMDecoder<X64Visitor>,
415420
void visit_I64RemS() {
416421
m_a.asm_pop_r64(X64Reg::rbx);
417422
m_a.asm_pop_r64(X64Reg::rax);
423+
m_a.asm_mov_r64_imm64(X64Reg::rdx, 0);
418424
m_a.asm_div_r64(X64Reg::rbx);
419425
m_a.asm_push_r64(X64Reg::rdx);
420426
}

0 commit comments

Comments
 (0)