diff --git a/rap/src/analysis/core/alias.rs b/rap/src/analysis/core/alias.rs index 84c047c..b8c2fb6 100644 --- a/rap/src/analysis/core/alias.rs +++ b/rap/src/analysis/core/alias.rs @@ -1 +1,83 @@ pub mod mop; + +use std::fmt; +use rustc_data_structures::fx::FxHashMap; +use rustc_hir::def_id::DefId; + +//struct to cache the results for analyzed functions. +pub type FnMap = FxHashMap; + +/* + * To store the alias relationships among arguments and return values. + * Each function may have multiple return instructions, leading to different RetAlias. + */ +#[derive(Debug, Clone)] +pub struct FnRetAlias { + pub arg_size: usize, + pub alias_vec: Vec, +} + +impl FnRetAlias { + pub fn new(arg_size: usize) -> FnRetAlias{ + Self { + arg_size: arg_size, + alias_vec: Vec::::new(), + } + } +} + +impl fmt::Display for FnRetAlias { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, + "[{}]", + self.alias_vec.iter() + .map(|alias| format!("{}", alias)) + .collect::>() + .join("") + ) + } +} + +/* + * To store the alias relationships among arguments and return values. + */ +#[derive(Debug,Clone)] +pub struct RetAlias{ + pub left_index: usize, + pub left_field_seq: Vec, + pub left_may_drop: bool, + pub left_need_drop: bool, + pub right_index: usize, + pub right_field_seq: Vec, + pub right_may_drop: bool, + pub right_need_drop: bool, +} + +impl RetAlias{ + pub fn new(left_index: usize, left_may_drop: bool, left_need_drop: bool, + right_index: usize, right_may_drop: bool, right_need_drop: bool) -> RetAlias{ + RetAlias { + left_index: left_index, + left_field_seq: Vec::::new(), + left_may_drop: left_may_drop, + left_need_drop: left_need_drop, + right_index: right_index, + right_field_seq: Vec::::new(), + right_may_drop: right_may_drop, + right_need_drop: right_need_drop, + } + } + + pub fn valuable(&self) -> bool{ + return self.left_may_drop && self.right_may_drop; + } +} + +impl fmt::Display for RetAlias { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, + "({},{})", + self.left_index, self.right_index + ) + } +} diff --git a/rap/src/analysis/core/alias/mop.rs b/rap/src/analysis/core/alias/mop.rs index b685e4a..f31f28f 100644 --- a/rap/src/analysis/core/alias/mop.rs +++ b/rap/src/analysis/core/alias/mop.rs @@ -7,16 +7,13 @@ use rustc_middle::ty::TyCtxt; use rustc_span::def_id::DefId; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashSet; -use crate::{rap_info, rap_debug}; +use crate::rap_info; use crate::utils::source::*; use graph::MopGraph; -use alias::FnRetAlias; +use crate::analysis::core::alias::FnMap; pub const VISIT_LIMIT:usize = 100; -//struct to cache the results for analyzed functions. -pub type FnMap = FxHashMap; - pub struct MopAlias<'tcx> { pub tcx: TyCtxt<'tcx>, pub fn_map: FnMap, diff --git a/rap/src/analysis/core/alias/mop/alias.rs b/rap/src/analysis/core/alias/mop/alias.rs index 2bf9073..fbdee85 100644 --- a/rap/src/analysis/core/alias/mop/alias.rs +++ b/rap/src/analysis/core/alias/mop/alias.rs @@ -2,12 +2,11 @@ use rustc_middle::ty; use rustc_middle::mir::{TerminatorKind, Operand, Place, ProjectionElem}; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::DefId; -use std::fmt; -use crate::{rap_info, rap_error}; +use crate::rap_error; use super::graph::*; use super::types::*; use super::mop::*; -use super::super::mop::FnMap; +use crate::analysis::core::alias::{FnMap, RetAlias}; impl<'tcx> MopGraph<'tcx> { /* alias analysis for a single block */ @@ -266,76 +265,3 @@ impl<'tcx> MopGraph<'tcx> { return field_id_seq; } } -/* - * To store the alias relationships among arguments and return values. - */ -#[derive(Debug,Clone)] -pub struct RetAlias{ - pub left_index: usize, - pub left_field_seq: Vec, - pub left_may_drop: bool, - pub left_need_drop: bool, - pub right_index: usize, - pub right_field_seq: Vec, - pub right_may_drop: bool, - pub right_need_drop: bool, -} - -impl RetAlias{ - pub fn new(left_index: usize, left_may_drop: bool, left_need_drop: bool, - right_index: usize, right_may_drop: bool, right_need_drop: bool) -> RetAlias{ - RetAlias { - left_index: left_index, - left_field_seq: Vec::::new(), - left_may_drop: left_may_drop, - left_need_drop: left_need_drop, - right_index: right_index, - right_field_seq: Vec::::new(), - right_may_drop: right_may_drop, - right_need_drop: right_need_drop, - } - } - - pub fn valuable(&self) -> bool{ - return self.left_may_drop && self.right_may_drop; - } -} - -impl fmt::Display for RetAlias { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, - "({},{})", - self.left_index, self.right_index - ) - } -} -/* - * To store the alias relationships among arguments and return values. - * Each function may have multiple return instructions, leading to different RetAlias. - */ -#[derive(Debug, Clone)] -pub struct FnRetAlias { - pub arg_size: usize, - pub alias_vec: Vec, -} - -impl FnRetAlias { - pub fn new(arg_size: usize) -> FnRetAlias{ - Self { - arg_size: arg_size, - alias_vec: Vec::::new(), - } - } -} - -impl fmt::Display for FnRetAlias { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, - "[{}]", - self.alias_vec.iter() - .map(|alias| format!("{}", alias)) - .collect::>() - .join("") - ) - } -} diff --git a/rap/src/analysis/core/alias/mop/graph.rs b/rap/src/analysis/core/alias/mop/graph.rs index 0b55fde..b9030a4 100644 --- a/rap/src/analysis/core/alias/mop/graph.rs +++ b/rap/src/analysis/core/alias/mop/graph.rs @@ -13,8 +13,8 @@ use rustc_data_structures::fx::FxHashMap; use rustc_middle::mir::Operand; use rustc_middle::mir::Rvalue; use rustc_span::Span; -use super::alias::*; use super::types::*; +use crate::analysis::core::alias::FnRetAlias; #[derive(PartialEq,Debug,Copy,Clone)] pub enum AssignType { diff --git a/rap/src/analysis/safedrop.rs b/rap/src/analysis/safedrop.rs index 871110e..624cee2 100644 --- a/rap/src/analysis/safedrop.rs +++ b/rap/src/analysis/safedrop.rs @@ -11,7 +11,8 @@ use rustc_hir::def_id::DefId; use graph::SafeDropGraph; use safedrop::*; -use crate::analysis::core::alias::mop::{MopAlias, FnMap}; +use crate::analysis::core::alias::mop::MopAlias; +use crate::analysis::core::alias::FnMap; pub struct SafeDrop<'tcx> { pub tcx: TyCtxt<'tcx>, diff --git a/rap/src/analysis/safedrop/alias.rs b/rap/src/analysis/safedrop/alias.rs index 519b4cf..ac3ecf2 100644 --- a/rap/src/analysis/safedrop/alias.rs +++ b/rap/src/analysis/safedrop/alias.rs @@ -5,8 +5,7 @@ use rustc_middle::mir::{TerminatorKind, Operand, Place, ProjectionElem}; use crate::rap_error; use super::types::*; use super::graph::*; -use crate::analysis::safedrop::FnMap; -use crate::analysis::core::alias::mop::alias::RetAlias; +use crate::analysis::core::alias::{FnMap, RetAlias}; impl<'tcx> SafeDropGraph<'tcx>{ /* alias analysis for a single block */ diff --git a/rap/src/analysis/safedrop/safedrop.rs b/rap/src/analysis/safedrop/safedrop.rs index 2b2f463..0310f1a 100644 --- a/rap/src/analysis/safedrop/safedrop.rs +++ b/rap/src/analysis/safedrop/safedrop.rs @@ -3,7 +3,7 @@ use rustc_middle::mir::{TerminatorKind, Operand}; use rustc_middle::mir::Operand::{Copy, Move, Constant}; use crate::{rap_error}; -use crate::analysis::core::alias::mop::{FnMap}; +use crate::analysis::core::alias::FnMap; use crate::analysis::safedrop::SafeDropGraph; pub const DROP:usize = 1634; diff --git a/test cases/senryx_tests/slice_from_raw_parts/Cargo.lock b/test cases/senryx_tests/slice_from_raw_parts/Cargo.lock deleted file mode 100644 index 4e9b0b6..0000000 --- a/test cases/senryx_tests/slice_from_raw_parts/Cargo.lock +++ /dev/null @@ -1,7 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "slice_from_raw_parts" -version = "0.1.0" diff --git a/test cases/senryx_tests/slice_from_raw_parts/Cargo.toml b/tests/senryx_tests/slice_from_raw_parts/Cargo.toml similarity index 100% rename from test cases/senryx_tests/slice_from_raw_parts/Cargo.toml rename to tests/senryx_tests/slice_from_raw_parts/Cargo.toml diff --git a/test cases/senryx_tests/slice_from_raw_parts/src/cfg.png b/tests/senryx_tests/slice_from_raw_parts/src/cfg.png similarity index 100% rename from test cases/senryx_tests/slice_from_raw_parts/src/cfg.png rename to tests/senryx_tests/slice_from_raw_parts/src/cfg.png diff --git a/test cases/senryx_tests/slice_from_raw_parts/src/main.rs b/tests/senryx_tests/slice_from_raw_parts/src/main.rs similarity index 100% rename from test cases/senryx_tests/slice_from_raw_parts/src/main.rs rename to tests/senryx_tests/slice_from_raw_parts/src/main.rs diff --git a/test cases/senryx_tests/slice_from_raw_parts/src/output.dot b/tests/senryx_tests/slice_from_raw_parts/src/output.dot similarity index 100% rename from test cases/senryx_tests/slice_from_raw_parts/src/output.dot rename to tests/senryx_tests/slice_from_raw_parts/src/output.dot