Skip to content

Commit 7d29c4f

Browse files
committed
Fix stack overflow when doing binary operation on integers of different sizes
1 parent 6d2c8ca commit 7d29c4f

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/cobalt/types/utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,15 @@ pub fn bin_op<'ctx>(loc: Location, (mut lhs, lloc): (Value<'ctx>, Location), (mu
662662
rhs.comp_val = Some(IntValue(if ru {ctx.builder.build_int_z_extend(val, ctx.context.custom_width_int_type(ls as u32), "")}
663663
else {ctx.builder.build_int_s_extend(val, ctx.context.custom_width_int_type(ls as u32), "")}));
664664
}
665+
rhs.data_type = Type::Int(ls, ru);
665666
bin_op(loc, (lhs, lloc), (rhs, rloc), op, ctx)
666667
},
667668
(Type::Int(ls, lu), Type::Int(rs, _)) if ls < rs => {
668669
if let (Some(IntValue(val)), false) = (lhs.value(ctx), ctx.is_const.get()) {
669670
lhs.comp_val = Some(IntValue(if lu {ctx.builder.build_int_z_extend(val, ctx.context.custom_width_int_type(rs as u32), "")}
670671
else {ctx.builder.build_int_s_extend(val, ctx.context.custom_width_int_type(rs as u32), "")}));
671672
}
673+
lhs.data_type = Type::Int(rs, lu);
672674
bin_op(loc, (lhs, lloc), (rhs, rloc), op, ctx)
673675
},
674676
(Type::Int(ls, lu), Type::Int(rs, ru)) if ls == rs => match op {

0 commit comments

Comments
 (0)