wasm: Fix unreachable paths
When the last instruction is a debug instruction, the type of it is void. Similarly for 'noreturn' emit an 'unreachable' instruction to tell the wasm-validator the path cannot be reached. Also respect the '--strip' flag in the self-hosted wasm linker and not emit a 'name' section when the flag is set to `true`.
This commit is contained in:
@@ -871,7 +871,8 @@ fn genFunc(self: *Self) InnerError!void {
|
||||
// we emit an unreachable instruction to tell the stack validator that part will never be reached.
|
||||
if (func_type.returns.len != 0 and self.air.instructions.len > 0) {
|
||||
const inst = @intCast(u32, self.air.instructions.len - 1);
|
||||
if (self.air.typeOfIndex(inst).isNoReturn()) {
|
||||
const last_inst_ty = self.air.typeOfIndex(inst);
|
||||
if (!last_inst_ty.hasRuntimeBitsIgnoreComptime() or last_inst_ty.isNoReturn()) {
|
||||
try self.addTag(.@"unreachable");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1897,7 +1897,7 @@ pub fn flushModule(self: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
|
||||
if (data_section_index) |data_index| {
|
||||
try self.emitDataRelocations(file, arena, data_index, symbol_table);
|
||||
}
|
||||
} else {
|
||||
} else if (!self.base.options.strip) {
|
||||
try self.emitNameSection(file, arena);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user