Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
nightly-2023-03-22 (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanventer authored Mar 23, 2023
1 parent c442647 commit 4a384a1
Show file tree
Hide file tree
Showing 15 changed files with 191 additions and 100 deletions.
75 changes: 43 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified binaries/summary_store.tar
Binary file not shown.
2 changes: 1 addition & 1 deletion checker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]

name = "mirai"
version = "1.1.6"
version = "1.1.7"
authors = ["Herman Venter <[email protected]>"]
description = "A static analysis tool for Rust, based on Abstract Interpretation of MIR"
repository = "https://github.com/facebookexperimental/MIRAI"
Expand Down
16 changes: 8 additions & 8 deletions checker/src/block_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
/// memory being read from and written to and size indicates how many bytes are being copied over.
#[logfn_inputs(TRACE)]
fn visit_copy_non_overlapping(&mut self, copy_info: &mir::CopyNonOverlapping<'tcx>) {
debug!("env {:?}", self.bv.current_environment);
let source_val = self.visit_operand(&copy_info.src);
let source_path =
Path::new_deref(Path::get_as_path(source_val), ExpressionType::NonPrimitive)
Expand Down Expand Up @@ -3139,9 +3138,12 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
let mut bytes_left_to_deserialize = bytes;
if let Ok(enum_ty_layout) = self.type_visitor().layout_of(ty) {
trace!("enum_ty_layout {:?}", enum_ty_layout);
let len = bytes.len();
let len = enum_ty_layout.size.bytes_usize();
let tag_length;
let data = if len < 2 {
let data = if len == 0 {
tag_length = 0;
0
} else if len < 2 {
tag_length = 1;
bytes[0] as u128
} else if len < 4 {
Expand Down Expand Up @@ -3335,9 +3337,7 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
self.bv.update_value_at(target_path, Rc::new(f.into()));
&bytes[8..]
},
TyKind::FnPtr(..)
| TyKind::RawPtr(rustc_middle::ty::TypeAndMut { .. })
| TyKind::Ref(..) => {
TyKind::RawPtr(rustc_middle::ty::TypeAndMut { .. }) | TyKind::Ref(..) => {
// serialized pointers are not the values pointed to, just some number.
// todo: figure out how to deference that number and deserialize the
// value to which this pointer refers.
Expand Down Expand Up @@ -3692,8 +3692,8 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
let substs = self
.type_visitor()
.specialize_substs(substs, &self.type_visitor().generic_argument_map);
if substs.len() == 3 {
let tuple_ty = substs[2].expect_ty();
if substs.len() >= 3 {
let tuple_ty = substs.last().unwrap().expect_ty();
let cv = self.get_constant_value_from_scalar(tuple_ty, data, size);
let cp = Path::get_as_path(cv);
let fr = self
Expand Down
23 changes: 17 additions & 6 deletions checker/src/body_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
active_calls_map: &'analysis mut HashMap<DefId, u64>,
type_cache: Rc<RefCell<TypeCache<'tcx>>>,
) -> BodyVisitor<'analysis, 'compilation, 'tcx> {
let tcx = crate_visitor.tcx;
let function_name = crate_visitor
.summary_cache
.get_summary_key_for(def_id)
.clone();
let id = rustc_middle::ty::WithOptConstParam::unknown(def_id);
let def = rustc_middle::ty::InstanceDef::Item(id);
let mir = crate_visitor.tcx.instance_mir(def);
let tcx = crate_visitor.tcx;
let mir = if tcx.is_const_fn_raw(def_id) {
tcx.mir_for_ctfe(def_id)
} else {
let id = rustc_middle::ty::WithOptConstParam::unknown(def_id);
let def = rustc_middle::ty::InstanceDef::Item(id);
tcx.instance_mir(def)
};
crate_visitor.call_graph.add_root(def_id);
BodyVisitor {
cv: crate_visitor,
Expand Down Expand Up @@ -834,6 +838,7 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
}
trace!("def_id {:?}", self.tcx.def_kind(self.def_id));
let saved_mir = self.mir;
let saved_def_id = self.def_id;
for (ordinal, constant_mir) in self.tcx.promoted_mir(self.def_id).iter().enumerate() {
self.mir = constant_mir;
self.type_visitor_mut().mir = self.mir;
Expand All @@ -844,6 +849,8 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
let mut result_root: Rc<Path> = Path::new_result();
let mut promoted_root: Rc<Path> =
Rc::new(PathEnum::PromotedConstant { ordinal }.into());
self.type_visitor_mut()
.set_path_rustc_type(promoted_root.clone(), result_rustc_type);
if self
.type_visitor()
.is_slice_pointer(result_rustc_type.kind())
Expand Down Expand Up @@ -910,6 +917,7 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
}
self.reset_visitor_state();
}
self.def_id = saved_def_id;
self.mir = saved_mir;
self.type_visitor_mut().mir = saved_mir;
environment
Expand Down Expand Up @@ -1300,8 +1308,11 @@ impl<'analysis, 'compilation, 'tcx> BodyVisitor<'analysis, 'compilation, 'tcx> {
// The right hand value has lost precision in such a way that we cannot
// even get its rustc type. In that case, let's try using the type of
// the left hand value.
self.type_visitor
.get_path_rustc_type(&tpath, self.current_span)
let t = self
.type_visitor
.get_path_rustc_type(&tpath, self.current_span);
self.type_visitor.set_path_rustc_type(path.clone(), t);
t
} else {
t
}
Expand Down
2 changes: 1 addition & 1 deletion checker/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn make_options_parser<'help>(running_test_harness: bool) -> Command<'help> {
// to construct this more then once per regular program run.
let mut parser = Command::new("MIRAI")
.no_binary_name(true)
.version("v1.1.6")
.version("v1.1.7")
.arg(Arg::new("single_func")
.long("single_func")
.takes_value(true)
Expand Down
10 changes: 5 additions & 5 deletions checker/src/type_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ impl<'tcx> TypeVisitor<'tcx> {
}
}
PathEnum::PhantomData => self.tcx.types.never,
PathEnum::PromotedConstant { .. } => {
debug!("path.value is {:?} at {:?}", path.value, current_span);
debug!("path_ty_cache {:?}", self.path_ty_cache);
self.tcx.types.never
}
PathEnum::Result => {
if self.mir.local_decls.is_empty() {
info!("result type wanted from function without result local");
Expand Down Expand Up @@ -662,11 +667,6 @@ impl<'tcx> TypeVisitor<'tcx> {
);
self.tcx.types.never
}
_ => {
info!("path.value is {:?} at {:?}", path.value, current_span);
info!("path_ty_cache {:?}", self.path_ty_cache);
self.tcx.types.never
}
}
}

Expand Down
14 changes: 10 additions & 4 deletions checker/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,16 @@ fn push_component_name(component_data: DefPathData, target: &mut String) {
pub fn def_id_as_qualified_name_str(tcx: TyCtxt<'_>, def_id: DefId) -> Rc<str> {
let mut name = format!("/{}/", crate_name(tcx, def_id));
name.push_str(&tcx.def_path_str(def_id));
let fn_ty = tcx.type_of(def_id).skip_binder();
if fn_ty.is_fn() {
if tcx.def_kind(def_id).is_fn_like() {
let fn_ty = tcx.type_of(def_id).skip_binder();
name.push('(');
let fn_sig = fn_ty.fn_sig(tcx).skip_binder();
let fn_sig = if fn_ty.is_fn() {
fn_ty.fn_sig(tcx).skip_binder()
} else if let ty::Closure(_, substs) = fn_ty.kind() {
substs.as_closure().sig().skip_binder()
} else {
unreachable!()
};
let mut first = true;
for param_ty in fn_sig.inputs() {
if first {
Expand Down Expand Up @@ -509,7 +515,7 @@ pub fn is_concrete(ty: &TyKind<'_>) -> bool {
}
}

/// Dumps a human readable MIR redendering of the function with the given DefId to standard output.
/// Dumps a human readable MIR rendering of the function with the given DefId to standard output.
pub fn pretty_print_mir(tcx: TyCtxt<'_>, def_id: DefId) {
if !matches!(
tcx.def_kind(def_id),
Expand Down
Loading

0 comments on commit 4a384a1

Please sign in to comment.