Skip to content

Commit 6816513

Browse files
committed
Only use bitcast in Builder::ret for non-native integers
1 parent 035ff85 commit 6816513

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/builder.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,15 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
539539

540540
fn ret(&mut self, mut value: RValue<'gcc>) {
541541
let expected_return_type = self.current_func().get_return_type();
542-
if !expected_return_type.is_compatible_with(value.get_type()) {
543-
// NOTE: due to opaque pointers now being used, we need to bitcast here.
544-
value = self.context.new_bitcast(self.___location, value, expected_return_type);
542+
let value_type = value.get_type();
543+
if !expected_return_type.is_compatible_with(value_type) {
544+
// NOTE: due to opaque pointers now being used, we need to (bit)cast here.
545+
if self.is_native_int_type(value_type) && self.is_native_int_type(expected_return_type)
546+
{
547+
value = self.context.new_cast(self.___location, value, expected_return_type);
548+
} else {
549+
value = self.context.new_bitcast(self.___location, value, expected_return_type);
550+
}
545551
}
546552
self.llbb().end_with_return(self.___location, value);
547553
}

0 commit comments

Comments
 (0)