Skip to content

Commit

Permalink
analyze: add --skip-pointee-defs-list option
Browse files Browse the repository at this point in the history
  • Loading branch information
spernsteiner committed Dec 3, 2024
1 parent 7f74d32 commit 5073cc4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 18 additions & 3 deletions c2rust-analyze/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,14 @@ fn get_force_rewrite_defs() -> io::Result<HashSet<DefId>> {
Ok(force_rewrite)
}

fn get_skip_pointee_defs() -> io::Result<HashSet<DefId>> {
let mut skip_pointee = HashSet::new();
if let Ok(path) = env::var("C2RUST_ANALYZE_SKIP_POINTEE_LIST") {
read_defs_list(&mut skip_pointee, &path)?;
}
Ok(skip_pointee)
}

/// Local information, specific to a single function. Many of the data structures we use for
/// the pointer analysis have a "global" part that's shared between all functions and a "local"
/// part that's specific to the function being analyzed; this struct contains only the local
Expand Down Expand Up @@ -1861,6 +1869,8 @@ fn do_pointee_type<'tcx>(
GlobalPointerTable::<PointeeTypes>::new(gacx.num_global_pointers());
let mut pointee_vars = pointee_type::VarTable::default();

let skip_pointee = get_skip_pointee_defs().unwrap();

for &ldid in all_fn_ldids {
if gacx.fn_analysis_invalid(ldid.to_def_id()) {
continue;
Expand All @@ -1872,9 +1882,14 @@ fn do_pointee_type<'tcx>(
let mir = mir.borrow();
let acx = gacx.function_context_with_data(&mir, info.acx_data.take());

let r = panic_detail::catch_unwind(AssertUnwindSafe(|| {
pointee_type::generate_constraints(&acx, &mir, &mut pointee_vars)
}));
let r = if !skip_pointee.contains(&ldid.to_def_id()) {
panic_detail::catch_unwind(AssertUnwindSafe(|| {
pointee_type::generate_constraints(&acx, &mir, &mut pointee_vars)
}))
} else {
// For defs in the skip_pointee set, build an empty constraint set.
Ok(pointee_type::ConstraintSet::default())
};

let local_pointee_types = LocalPointerTable::new(acx.local_ptr_base(), acx.num_pointers());
info.acx_data.set(acx.into_data());
Expand Down
9 changes: 9 additions & 0 deletions c2rust-analyze/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ struct Args {
#[clap(long)]
force_rewrite_defs_list: Option<PathBuf>,

/// Read a list of defs on which the pointee type analysis should be skipped.
#[clap(long)]
skip_pointee_defs_list: Option<PathBuf>,

/// `cargo` args.
cargo_args: Vec<OsString>,
}
Expand Down Expand Up @@ -398,6 +402,7 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
use_manual_shims,
fixed_defs_list,
force_rewrite_defs_list,
skip_pointee_defs_list,
cargo_args,
} = Args::parse();

Expand Down Expand Up @@ -449,6 +454,10 @@ fn cargo_wrapper(rustc_wrapper: &Path) -> anyhow::Result<()> {
cmd.env("C2RUST_ANALYZE_FORCE_REWRITE_LIST", force_rewrite_defs_list);
}

if let Some(ref skip_pointee_defs_list) = skip_pointee_defs_list {
cmd.env("C2RUST_ANALYZE_SKIP_POINTEE_LIST", skip_pointee_defs_list);
}

if !rewrite_paths.is_empty() {
let rewrite_paths = rewrite_paths.join(OsStr::new(","));
cmd.env("C2RUST_ANALYZE_REWRITE_PATHS", rewrite_paths);
Expand Down

0 comments on commit 5073cc4

Please sign in to comment.