[spv-out] return Null by default

This commit is contained in:
Dzmitry Malyshau authored and Dzmitry Malyshau committed 2021-04-25 01:07:59 -04:00
1 parent 77a64da189
commit 1cc770a7d8
3 files changed
+21 -3

No files matched your search

+7
View File
@@ -350,6 +350,13 @@ impl super::Instruction {
// Constant-Creation Instructions
//
pub(super) fn constant_null(result_type_id: Word, id: Word) -> Self {
let mut instruction = Self::new(Op::ConstantNull);
instruction.set_type(result_type_id);
instruction.set_result(id);
instruction
}
pub(super) fn constant_true(result_type_id: Word, id: Word) -> Self {
let mut instruction = Self::new(Op::ConstantTrue);
instruction.set_type(result_type_id);
+13 -2
View File
@@ -2741,8 +2741,19 @@ impl Writer {
Some(id) => Instruction::branch(id),
// This can happen if the last branch had all the paths
// leading out of the graph (i.e. returning).
// So it doesn't matter what we do here, but it has to be valid.
None => Instruction::branch(label_id),
// Or it may be the end of the function.
None => match ir_function.result {
Some(ref result) if function.entry_point_context.is_none() => {
// create a Null and return it
let null_id = self.id_gen.next();
let type_id =
self.get_type_id(&ir_module.types, LookupType::Handle(result.ty))?;
Instruction::constant_null(type_id, null_id)
.to_words(&mut self.logical_layout.declarations);
Instruction::return_value(null_id)
}
_ => Instruction::return_void(),
},
});
}
+1 -1
View File
@@ -76,5 +76,5 @@ OpReturn
OpStore %22 %44
OpReturn
%37 = OpLabel
OpBranch %29
OpReturn
OpFunctionEnd