Skip to content

Commit be48d74

Browse files
committed
reachability: skip instance without body; only collect Item instance
********* "demo" [Rlib] has reached 8 instances ********* "test" ("src/lib.rs:12:1: 12:26") => "#[Safety::inner(UnReachable, kind = \"precond\", memo =\n\"It's undefined behavior to reach code marked with this intrinsic function.\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(Init(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be initialized first!\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(InBound(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be within the length.\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(ValidNum(self.len * sizeof(u8), [0, isize :: MAX]), kind =\n\"precond\", memo =\n\"Slice length can't exceed isize::MAX due to allocation limit.\")]\n" "MyStruct::get" ("src/lib.rs:40:5: 40:42") => "#[Safety::inner(Alias(self.ptr), kind = \"hazard\", memo =\n\"Make sure don't alias the ptr.\")]\n" ********* "demo" [Executable] has reached 18 instances ********* "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(Init(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be initialized first!\")]\n" "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(InBound(self.ptr, u8, self.len), kind = \"precond\", memo =\n\"The ptr must be within the length.\")]\n" "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(ValidNum(self.len * sizeof(u8), [0, isize :: MAX]), kind =\n\"precond\", memo =\n\"Slice length can't exceed isize::MAX due to allocation limit.\")]\n" "demo::MyStruct::get" ("/home/gh-zjp-CN/tag-std/demo/rustc_driver/tests/basic/src/lib.rs:40:5: 40:42") => "#[Safety::inner(Alias(self.ptr), kind = \"hazard\", memo =\n\"Make sure don't alias the ptr.\")]\n"
1 parent c7220ec commit be48d74

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

demo/rustc_driver/src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ use rustc_hir::Attribute;
1515
use rustc_middle::ty::TyCtxt;
1616
use stable_mir::{
1717
CrateDef, ItemKind,
18-
mir::{MirVisitor, mono::Instance, visit::Location},
18+
mir::{
19+
MirVisitor,
20+
mono::{Instance, InstanceKind},
21+
visit::Location,
22+
},
1923
rustc_internal::internal,
2024
ty::Ty,
2125
};
@@ -62,7 +66,10 @@ struct Reachability {
6266

6367
impl Reachability {
6468
fn add_instance(&mut self, instance: Instance) {
65-
if self.instances.insert(instance) {
69+
if self.instances.insert(instance)
70+
&& instance.has_body()
71+
&& matches!(instance.kind, InstanceKind::Item)
72+
{
6673
// recurse if this is the first time of insertion
6774
if let Some(body) = instance.body() {
6875
self.visit_body(&body);
@@ -92,7 +99,7 @@ fn print_tag_std_attrs_through_internal_apis(tcx: TyCtxt<'_>, instance: &Instanc
9299
});
93100
for attr in tool_attrs {
94101
println!(
95-
"{fn_name:?} ({span:?}) => {attr:?}\n",
102+
"{fn_name:?} ({span:?})\n => {attr:?}\n",
96103
fn_name = instance.name(),
97104
span = instance.def.span().diagnostic(),
98105
attr = rustc_hir_pretty::attribute_to_string(&tcx, attr)

0 commit comments

Comments
 (0)