Skip to content

Commit 28bcbcd

Browse files
authored
Fixes dead code validation logic near the if. (bytecodealliance#127)
1 parent b56f91d commit 28bcbcd

3 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/operators_validator.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ impl FuncState {
135135
}
136136
};
137137
if block_type == BlockType::If {
138-
self.stack_types.pop();
138+
let last_block = self.blocks.last().unwrap();
139+
if !last_block.is_stack_polymorphic()
140+
|| self.stack_types.len() > last_block.stack_starts_at
141+
{
142+
self.stack_types.pop();
143+
}
144+
assert!(self.stack_types.len() >= last_block.stack_starts_at);
139145
}
140146
for (i, ty) in start_types.iter().rev().enumerate() {
141147
if !self.assert_stack_type_at(i, *ty) {

src/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod simple_tests {
4545
data
4646
}
4747

48+
#[allow(dead_code)]
4849
fn scan_tests_files(prefix: &str) -> Vec<PathBuf> {
4950
let mut files = Vec::new();
5051

tests/issue126.wasm

41 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)