Skip to content

Commit 035ff85

Browse files
committed
Fix intcast to use the is_signed parameter
1 parent e3a6469 commit 035ff85

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/builder.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,11 +1278,19 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12781278

12791279
fn intcast(
12801280
&mut self,
1281-
value: RValue<'gcc>,
1281+
mut value: RValue<'gcc>,
12821282
dest_typ: Type<'gcc>,
1283-
_is_signed: bool,
1283+
is_signed: bool,
12841284
) -> RValue<'gcc> {
1285-
// NOTE: is_signed is for value, not dest_typ.
1285+
let value_type = value.get_type();
1286+
if is_signed && !value_type.is_signed(self.cx) {
1287+
let signed_type = value_type.to_signed(self.cx);
1288+
value = self.gcc_int_cast(value, signed_type);
1289+
} else if !is_signed && value_type.is_signed(self.cx) {
1290+
let unsigned_type = value_type.to_unsigned(self.cx);
1291+
value = self.gcc_int_cast(value, unsigned_type);
1292+
}
1293+
12861294
self.gcc_int_cast(value, dest_typ)
12871295
}
12881296

0 commit comments

Comments
 (0)