Skip to content

Commit

Permalink
Update to nightly-2023-12-31 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
hermanventer authored Nov 13, 2024
1 parent 02d4c5c commit fd712f7
Show file tree
Hide file tree
Showing 19 changed files with 219 additions and 165 deletions.
203 changes: 91 additions & 112 deletions Cargo.lock

Large diffs are not rendered by default.

Binary file modified binaries/summary_store.tar
Binary file not shown.
102 changes: 86 additions & 16 deletions checker/src/block_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,12 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
mir::CastKind::Transmute => {
let source_type = self.get_operand_rustc_type(operand);
let source_value = self.visit_operand(operand);
let source_path = Path::get_as_path(source_value);
let source_path = Path::get_as_path(source_value.clone());
let path = if source_value.is_function() {
Path::new_function(path)
} else {
path
};
self.bv.copy_and_transmute(
source_path,
source_type,
Expand Down Expand Up @@ -2973,16 +2978,40 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
// The Rust compiler should ensure this.
assume!(alloc_len > offset_bytes);
let size = alloc_len - offset_bytes;
let bytes = alloc
.inner()
.get_bytes_strip_provenance(
&self.bv.tcx,
alloc_range(
ptr.into_parts().1,
rustc_target::abi::Size::from_bytes(size),
),
)
.unwrap();
let range = alloc_range(
ptr.into_parts().1,
rustc_target::abi::Size::from_bytes(size),
);
let bytes = if size > 0
&& alloc.inner().provenance().range_empty(range, &self.bv.tcx)
{
alloc
.inner()
.get_bytes_strip_provenance(&self.bv.tcx, range)
.unwrap()
} else {
let mut bytes = alloc.inner().get_bytes_unchecked(range);
if let Some(p) = alloc.inner().provenance().provenances().next() {
match self.bv.tcx.try_get_global_alloc(p.alloc_id()) {
Some(GlobalAlloc::Memory(alloc)) => {
let size = alloc.inner().len() as u64;
let range = alloc_range(
rustc_target::abi::Size::from_bytes(0),
rustc_target::abi::Size::from_bytes(size),
);
bytes = alloc
.inner()
.get_bytes_strip_provenance(&self.bv.tcx, range)
.unwrap();
}
_ => assume_unreachable!(
"ConstValue::Scalar with type {:?}",
lty
),
}
}
bytes
};
match lty.kind() {
TyKind::Array(elem_type, length) => {
let length = self.bv.get_array_length(length);
Expand All @@ -2993,8 +3022,8 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
);
array_value
}
TyKind::Ref(_, t, _) => {
if let TyKind::Array(elem_type, length) = t.kind() {
TyKind::Ref(_, t, _) => match t.kind() {
TyKind::Array(elem_type, length) => {
let length = self.bv.get_array_length(length);
let (_, array_path) =
self.get_heap_array_and_path(lty, size as usize);
Expand All @@ -3005,10 +3034,34 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
*elem_type,
);
AbstractValue::make_reference(array_path)
} else {
assume_unreachable!("ConstValue::Ptr with type {:?}", lty);
}
}
TyKind::Adt(..) => {
let (_heap_val, heap_path) = self.bv.get_new_heap_block(
Rc::new((bytes.len() as u128).into()),
Rc::new(1u128.into()),
false,
lty,
);
let bytes_left_to_deserialize = self
.deserialize_constant_bytes(heap_path.clone(), bytes, *t);
if !bytes_left_to_deserialize.is_empty() {
debug!("span: {:?}", self.bv.current_span);
debug!("type kind {:?}", lty.kind());
debug!(
"constant value did not serialize correctly {:?}",
val
);
}
AbstractValue::make_reference(heap_path)
}
_ => {
assume_unreachable!(
"ConstValue::Ptr with type {:?} {:?}",
lty,
t.kind()
);
}
},
_ => {
assume_unreachable!("ConstValue::Scalar with type {:?}", lty);
}
Expand Down Expand Up @@ -3376,6 +3429,23 @@ impl<'block, 'analysis, 'compilation, 'tcx> BlockVisitor<'block, 'analysis, 'com
self.bv.update_value_at(target_path, Rc::new(f.into()));
&bytes[8..]
},
TyKind::Ref(_, t, _) if matches!(t.kind(), TyKind::Str) => {
let s = std::str::from_utf8(bytes).expect("string should be serialized as utf8");
let string_const = &mut self.bv.cv.constant_value_cache.get_string_for(s);
let string_val: Rc<AbstractValue> = Rc::new(string_const.clone().into());
let len_val: Rc<AbstractValue> =
Rc::new(ConstantDomain::U128(s.len() as u128).into());

let str_path = Path::new_computed(string_val.clone());
self.bv.update_value_at(str_path.clone(), string_val);

let len_path = Path::new_length(str_path.clone());
self.bv.update_value_at(len_path, len_val);

self.bv
.update_value_at(target_path, AbstractValue::make_reference(str_path));
&[]
}
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
Expand Down
2 changes: 2 additions & 0 deletions checker/src/call_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3035,6 +3035,8 @@ impl<'call, 'block, 'analysis, 'compilation, 'tcx>
}
}
}
} else {
return Rc::from("dummy argument");
}
if self.block_visitor.bv.check_for_errors {
let warning = self.block_visitor.bv.cv.session.dcx().struct_span_warn(
Expand Down
15 changes: 9 additions & 6 deletions checker/src/cargo_mirai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ pub fn main() {
println!("{CARGO_MIRAI_HELP}");
return;
}
if std::env::args().any(|a| a == "--version" || a == "-V") {
let version_info = rustc_tools_util::get_version_info!();
println!("{version_info}");
return;
}

match std::env::args().nth(1).as_ref().map(AsRef::<str>::as_ref) {
Some(s) if s.ends_with("mirai") || s.ends_with("mirai.exe") => {
// Get here for the top level cargo execution, i.e. "cargo mirai".
if std::env::args().any(|a| a == "--version" || a == "-V") {
let version_info = rustc_tools_util::get_version_info!();
println!("{version_info}");
return;
}
call_cargo();
}
Some(s) if s.ends_with("rustc") || s.ends_with("rustc.exe") => {
// 'cargo rustc ..' redirects here because RUSTC_WRAPPER points to this binary.
// execute rustc with MIRAI applicable parameters for dependencies and call MIRAI
// to analyze targets in the current package.
if std::env::args().any(|a| a == "--version" || a == "-V") {
call_rustc();
return;
}
call_rustc_or_mirai();
}
Some(arg) => {
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ commit;
],
"callables": [
{
"name": "/fnptr/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr[7a8d]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr[f94d]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 9,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ commit;
],
"callables": [
{
"name": "/fnptr_clean/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ fnptr_clean[1be2]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_clean/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ fnptr_clean[6569]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 14,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_deduplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ commit;
],
"callables": [
{
"name": "/fnptr_deduplicate/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_deduplicate[535a]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_deduplicate/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_deduplicate[9d1b]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 10,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ commit;
],
"callables": [
{
"name": "/fnptr_dom/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_dom[7513]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []),&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:8 ~ fnptr_dom[7513]::fn1::'_#1), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_dom/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_dom[cff3]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []),&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:8 ~ fnptr_dom[cff3]::fn1::'_#1), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 9,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_dom_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ commit;
],
"callables": [
{
"name": "/fnptr_dom_loop/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ fnptr_dom_loop[bcc6]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []),&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:9 ~ fnptr_dom_loop[bcc6]::fn1::'_#1), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_dom_loop/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ fnptr_dom_loop[212a]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []),&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:9 ~ fnptr_dom_loop[212a]::fn1::'_#1), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 9,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_dom_loop_souffle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ digraph {
],
"callables": [
{
"name": "/fnptr_dom_loop_souffle/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ fnptr_dom_loop_souffle[9ccc]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []),&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:9 ~ fnptr_dom_loop_souffle[9ccc]::fn1::'_#1), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_dom_loop_souffle/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ fnptr_dom_loop_souffle[e6c4]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []),&ReBound(DebruijnIndex(0), BoundRegion { var: 1, kind: BrNamed(DefId(0:9 ~ fnptr_dom_loop_souffle[e6c4]::fn1::'_#1), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 10,
"local": true
Expand Down
18 changes: 9 additions & 9 deletions checker/tests/call_graph/fnptr_fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ commit;
/* EXPECTED:CALL_SITES{
"files": [
"tests/call_graph/fnptr_fold.rs",
"/rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/std/src/io/stdio.rs",
"/rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/core/src/fmt/mod.rs",
"/rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/core/src/slice/mod.rs",
"/rustc/3cdd004e55c869faa2b7b25efd3becf50346e7d6/library/core/src/ptr/metadata.rs"
"/rustc/2a3e63551fe21458637480a97b65a2d15dec8062/library/std/src/io/stdio.rs",
"/rustc/2a3e63551fe21458637480a97b65a2d15dec8062/library/core/src/fmt/mod.rs",
"/rustc/2a3e63551fe21458637480a97b65a2d15dec8062/library/core/src/slice/mod.rs",
"/rustc/2a3e63551fe21458637480a97b65a2d15dec8062/library/core/src/ptr/metadata.rs"
],
"callables": [
{
"name": "/fnptr_fold/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_fold[e0d1]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_fold/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_fold[33be]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 10,
"local": true
Expand All @@ -99,25 +99,25 @@ commit;
"local": true
},
{
"name": "/std/std::io::_print(std::fmt::Arguments<ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(1:12928 ~ std[f878]::io::stdio::_print::'_), '_) })>)->()",
"name": "/std/std::io::_print(std::fmt::Arguments<ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(1:12928 ~ std[ddb8]::io::stdio::_print::'_), '_) })>)->()",
"file_index": 1,
"first_line": 1096,
"local": false
},
{
"name": "/core/std::fmt::Arguments::<'a>::new_const(&ReEarlyParam(DefId(2:9935 ~ core[32af]::fmt::{impl#2}::'a), 0, 'a) [&ReStatic str])->std::fmt::Arguments<ReEarlyParam(DefId(2:9935 ~ core[32af]::fmt::{impl#2}::'a), 0, 'a)>",
"name": "/core/std::fmt::Arguments::<'a>::new_const(&ReEarlyParam(DefId(2:9935 ~ core[c4b9]::fmt::{impl#2}::'a), 0, 'a) [&ReStatic str])->std::fmt::Arguments<ReEarlyParam(DefId(2:9935 ~ core[c4b9]::fmt::{impl#2}::'a), 0, 'a)>",
"file_index": 2,
"first_line": 321,
"local": true
},
{
"name": "/core/core::slice::<impl [T]>::len(&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(2:59819 ~ core[32af]::slice::{impl#0}::len::'_), '_) }) [T/#0])->usize",
"name": "/core/core::slice::<impl [T]>::len(&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(2:59819 ~ core[c4b9]::slice::{impl#0}::len::'_), '_) }) [T/#0])->usize",
"file_index": 3,
"first_line": 137,
"local": true
},
{
"name": "/core/std::ptr::metadata(*const T/#0)->Alias(Projection, AliasTy { args: [T/#0], def_id: DefId(2:1880 ~ core[32af]::ptr::metadata::Pointee::Metadata) })",
"name": "/core/std::ptr::metadata(*const T/#0)->Alias(Projection, AliasTy { args: [T/#0], def_id: DefId(2:1880 ~ core[c4b9]::ptr::metadata::Pointee::Metadata) })",
"file_index": 4,
"first_line": 94,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ commit;
"local": true
},
{
"name": "/fnptr_loop/fn2(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_loop[ae6f]::fn2::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_loop/fn2(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_loop[3a22]::fn2::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 12,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/fnptr_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ commit;
],
"callables": [
{
"name": "/fnptr_slice/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_slice[ebf1]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"name": "/fnptr_slice/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ fnptr_slice[a3bc]::fn1::'_), '_) }) Binder(fn(u32) -> u32, []))->u32",
"file_index": 0,
"first_line": 10,
"local": true
Expand Down
2 changes: 1 addition & 1 deletion checker/tests/call_graph/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ commit;
"local": true
},
{
"name": "/generic/Gen::<T>::bar(&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:12 ~ generic[01cf]::{impl#0}::bar::'_), '_) }) Gen<T/#0>,T/#0)->()",
"name": "/generic/Gen::<T>::bar(&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:12 ~ generic[3cba]::{impl#0}::bar::'_), '_) }) Gen<T/#0>,T/#0)->()",
"file_index": 0,
"first_line": 14,
"local": true
Expand Down
6 changes: 3 additions & 3 deletions checker/tests/call_graph/static_deduplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ commit;
],
"callables": [
{
"name": "/static_deduplicate/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ static_deduplicate[671b]::fn1::'_), '_) }) str)->(u32, &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ static_deduplicate[671b]::fn1::'_), '_) }) str)",
"name": "/static_deduplicate/fn1(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ static_deduplicate[ee08]::fn1::'_), '_) }) str)->(u32, &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:7 ~ static_deduplicate[ee08]::fn1::'_), '_) }) str)",
"file_index": 0,
"first_line": 10,
"local": true
},
{
"name": "/static_deduplicate/fn2(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ static_deduplicate[671b]::fn2::'_), '_) }) str)->(u32, &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ static_deduplicate[671b]::fn2::'_), '_) }) str)",
"name": "/static_deduplicate/fn2(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ static_deduplicate[ee08]::fn2::'_), '_) }) str)->(u32, &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:8 ~ static_deduplicate[ee08]::fn2::'_), '_) }) str)",
"file_index": 0,
"first_line": 13,
"local": true
},
{
"name": "/static_deduplicate/fn3(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:9 ~ static_deduplicate[671b]::fn3::'_), '_) }) str)->(u32, &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:9 ~ static_deduplicate[671b]::fn3::'_), '_) }) str)",
"name": "/static_deduplicate/fn3(u32,&ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:9 ~ static_deduplicate[ee08]::fn3::'_), '_) }) str)->(u32, &ReBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:9 ~ static_deduplicate[ee08]::fn3::'_), '_) }) str)",
"file_index": 0,
"first_line": 16,
"local": true
Expand Down
Loading

0 comments on commit fd712f7

Please sign in to comment.