Skip to content

Commit 943804b

Browse files
committed
Avoid creating locals for unrechable terminators.
1 parent 7e84472 commit 943804b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/builder.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,8 +656,20 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
656656
self.block.add_eval(self.location, self.context.new_call(self.location, func, &[]));
657657
let return_type = self.block.get_function().get_return_type();
658658
let void_type = self.context.new_type::<()>();
659+
#[cfg(feature = "master")]
660+
let is_float = return_type.is_floating_point();
661+
#[cfg(not(feature = "master"))]
662+
let is_float = false;
659663
if return_type == void_type {
660664
self.block.end_with_void_return(self.location)
665+
}
666+
// For ints, floats and pointers, we can avoid creating the temporary local, and just return 0 / null.
667+
// This should have no effect on runtime: GCC already knows that everything after __builtin_unreachable
668+
// is unreachable.
669+
else if self.is_native_int_type(return_type) || is_float {
670+
self.block.end_with_return(self.location, self.context.new_rvalue_zero(return_type))
671+
} else if return_type.get_pointee().is_some() {
672+
self.block.end_with_return(self.location, self.context.new_null(return_type))
661673
} else {
662674
let return_value =
663675
self.current_func().new_local(self.location, return_type, "unreachableReturn");

0 commit comments

Comments
 (0)