Skip to content

Commit

Permalink
handle char & -1 tag
Browse files Browse the repository at this point in the history
  • Loading branch information
Medowhill committed May 27, 2024
1 parent fed3de7 commit 48b4085
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/must_analysis/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'tcx> Analyzer<'tcx, '_, '_> {
Operand::Constant(box constant) => match constant.literal {
ConstantKind::Ty(_) => unreachable!(),
ConstantKind::Unevaluated(constant, ty) => {
if ty.is_integral() {
if ty.is_integral() || ty.is_char() {
if let Ok(v) = self.tcx.const_eval_poly(constant.def) {
self.transfer_const_value(v, ty)
} else {
Expand Down Expand Up @@ -265,6 +265,7 @@ impl<'tcx> Analyzer<'tcx, '_, '_> {
};
OpVal::Int(v)
}
TyKind::Char => OpVal::Int(i.try_to_u32().unwrap() as _),
_ => OpVal::Other,
},
Scalar::Ptr(ptr, _) => match self.tcx.global_alloc(ptr.provenance) {
Expand Down Expand Up @@ -850,6 +851,7 @@ macro_rules! create_cast_fn {
UintTy::U128 => n as $typ as u128,
},
TyKind::Bool => (n != 0) as $typ as u128,
TyKind::Char => (n as u32) as $typ as u128,
_ => panic!(),
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/tag_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,9 @@ impl {} {{
&mut get_tag_method,
"
{}::{} => {},",
tu.name, variant_name, t
tu.name,
variant_name,
tag_to_string(*t, &field_ty),
)
.unwrap();
write!(
Expand Down Expand Up @@ -1547,6 +1549,8 @@ fn get_root<'tcx>(expr: &'tcx Expr<'tcx>) -> &'tcx Expr<'tcx> {
fn tag_to_string(tag: Tag, ty: &str) -> String {
if ty == "bool" {
(tag.0 != 0).to_string()
} else if ty.ends_with("c_int") {
(tag.0 as i32).to_string()
} else {
tag.to_string()
}
Expand Down

0 comments on commit 48b4085

Please sign in to comment.