Skip to content

Commit 03e66b6

Browse files
florianhartungwucke13
authored andcommitted
feat: implement unreachable instruction
Signed-off-by: Florian Hartung <florian.hartung@dlr.de>
1 parent 3134b86 commit 03e66b6

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/core/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub enum RuntimeError {
3030
UnmetImport,
3131
UndefinedTableIndex,
3232
// "undefined element" <- as-call_indirect-last
33-
// "unreachable"
33+
ReachedUnreachable,
3434
}
3535

3636
#[derive(Debug, PartialEq, Eq, Clone)]
@@ -314,6 +314,9 @@ impl Display for RuntimeError {
314314
RuntimeError::UndefinedTableIndex => {
315315
f.write_str("Indirect call: table index out of bounds")
316316
}
317+
RuntimeError::ReachedUnreachable => {
318+
f.write_str("an unreachable statement was reached, triggered a trap")
319+
}
317320
}
318321
}
319322
}

src/execution/interpreter_loop.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,9 @@ pub(super) fn run<H: HookSet>(
378378
val
379379
)
380380
}
381+
UNREACHABLE => {
382+
return Err(RuntimeError::ReachedUnreachable);
383+
}
381384
I32_LOAD => {
382385
let memarg = MemArg::read_unvalidated(wasm);
383386
let relative_address: u32 = stack.pop_value(ValType::NumType(NumType::I32)).into();

tests/specification/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub fn to_wasm_testsuite_string(runtime_error: RuntimeError) -> Result<String, B
7878
RuntimeError::FunctionNotFound => not_represented,
7979
RuntimeError::StackSmash => not_represented,
8080
RuntimeError::BadConversionToInteger => Ok("invalid conversion to integer"),
81+
RuntimeError::ReachedUnreachable => Ok("unreachable"),
8182

8283
RuntimeError::MemoryAccessOutOfBounds => Ok("out of bounds memory access"),
8384
RuntimeError::TableAccessOutOfBounds => Ok("out of bounds table access"),

0 commit comments

Comments
 (0)