From 626ee6337d0d4b66e3fefdb7dff2276e6c01e76d Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Mon, 15 May 2023 11:47:55 -0700 Subject: [PATCH 1/3] Replace `if cfg!(kani)` by `#[cfg(kani)]` In previous version of rustc, they would have similar behavior even in debug mode, where all the logic from a `false` evaluation would be pruned. This is no longer true in the current rustc release candidate. --- bolero-engine/src/target_location.rs | 105 +++++++++++++++------------ 1 file changed, 58 insertions(+), 47 deletions(-) diff --git a/bolero-engine/src/target_location.rs b/bolero-engine/src/target_location.rs index 3f1e0c6f..8ad02dab 100644 --- a/bolero-engine/src/target_location.rs +++ b/bolero-engine/src/target_location.rs @@ -28,20 +28,18 @@ pub struct TargetLocation { impl TargetLocation { pub fn should_run(&self) -> bool { - if cfg!(kani) { - return true; - } - - // cargo-bolero needs to resolve information about the target - if let Ok(mode) = ::std::env::var("CARGO_BOLERO_SELECT") { - match mode.as_str() { - "all" => self.print(), - "one" if self.is_exact_match() => self.print(), - _ => {} + #[cfg(not(kani))] + { + // cargo-bolero needs to resolve information about the target + if let Ok(mode) = ::std::env::var("CARGO_BOLERO_SELECT") { + match mode.as_str() { + "all" => self.print(), + "one" if self.is_exact_match() => self.print(), + _ => {} + } + return false; } - return false; } - true } @@ -65,59 +63,72 @@ impl TargetLocation { } pub fn abs_path(&self) -> Option { - if cfg!(kani) { - return None; + #[cfg(kani)] + { + None } - let file = Path::new(self.file); - - #[cfg(not(miri))] // miri does not currently support this call + #[cfg(not(kani))] { - if let Ok(file) = file.canonicalize() { - return Some(file); - } - } + let file = Path::new(self.file); - Path::new(self.manifest_dir) - .ancestors() - .find_map(|ancestor| { - let path = ancestor.join(file); - if path.exists() { - Some(path) - } else { - None + #[cfg(not(miri))] // miri does not currently support this call + { + if let Ok(file) = file.canonicalize() { + return Some(file); } - }) + } + + Path::new(self.manifest_dir) + .ancestors() + .find_map(|ancestor| { + let path = ancestor.join(file); + if path.exists() { + Some(path) + } else { + None + } + }) + } } pub fn work_dir(&self) -> Option { - if cfg!(kani) { - return None; + #[cfg(kani)] + { + None } - let mut work_dir = self.abs_path()?; - work_dir.pop(); + #[cfg(not(kani))] + { - if !self.is_harnessed() { - return Some(work_dir); - } + let mut work_dir = self.abs_path()?; + work_dir.pop(); - work_dir.push("__fuzz__"); - if let Some(test_name) = self.test_name.as_ref() { - work_dir.push(test_name); - } else { - work_dir.push(self.fuzz_dir()); - } + if !self.is_harnessed() { + return Some(work_dir); + } - Some(work_dir) + work_dir.push("__fuzz__"); + if let Some(test_name) = self.test_name.as_ref() { + work_dir.push(test_name); + } else { + work_dir.push(self.fuzz_dir()); + } + + Some(work_dir) + } } pub fn is_harnessed(&self) -> bool { - if cfg!(kani) { - return false; + #[cfg(kani)] + { + false } - is_harnessed(self.item_path) + #[cfg(not(kani))] + { + is_harnessed(self.item_path) + } } fn fuzz_dir(&self) -> String { From 186372ccb62454196fde45c6f1a6d2370b83146a Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Mon, 15 May 2023 12:37:39 -0700 Subject: [PATCH 2/3] Run cargo format --- bolero-engine/src/target_location.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/bolero-engine/src/target_location.rs b/bolero-engine/src/target_location.rs index 8ad02dab..2c19508b 100644 --- a/bolero-engine/src/target_location.rs +++ b/bolero-engine/src/target_location.rs @@ -100,7 +100,6 @@ impl TargetLocation { #[cfg(not(kani))] { - let mut work_dir = self.abs_path()?; work_dir.pop(); From 7bfbf1b3d3eae6be9c39218ba0c0aab8536fb08b Mon Sep 17 00:00:00 2001 From: "Celina G. Val" Date: Mon, 15 May 2023 13:18:33 -0700 Subject: [PATCH 3/3] Put Kani specific implementation in separate functions --- bolero-engine/src/target_location.rs | 117 +++++++++++++-------------- 1 file changed, 57 insertions(+), 60 deletions(-) diff --git a/bolero-engine/src/target_location.rs b/bolero-engine/src/target_location.rs index 2c19508b..365765bc 100644 --- a/bolero-engine/src/target_location.rs +++ b/bolero-engine/src/target_location.rs @@ -27,18 +27,21 @@ pub struct TargetLocation { } impl TargetLocation { + #[cfg(kani)] pub fn should_run(&self) -> bool { - #[cfg(not(kani))] - { - // cargo-bolero needs to resolve information about the target - if let Ok(mode) = ::std::env::var("CARGO_BOLERO_SELECT") { - match mode.as_str() { - "all" => self.print(), - "one" if self.is_exact_match() => self.print(), - _ => {} - } - return false; + true + } + + #[cfg(not(kani))] + pub fn should_run(&self) -> bool { + // cargo-bolero needs to resolve information about the target + if let Ok(mode) = ::std::env::var("CARGO_BOLERO_SELECT") { + match mode.as_str() { + "all" => self.print(), + "one" if self.is_exact_match() => self.print(), + _ => {} } + return false; } true } @@ -62,72 +65,66 @@ impl TargetLocation { ); } + #[cfg(kani)] pub fn abs_path(&self) -> Option { - #[cfg(kani)] - { - None - } + None + } - #[cfg(not(kani))] - { - let file = Path::new(self.file); + #[cfg(not(kani))] + pub fn abs_path(&self) -> Option { + let file = Path::new(self.file); - #[cfg(not(miri))] // miri does not currently support this call - { - if let Ok(file) = file.canonicalize() { - return Some(file); - } + #[cfg(not(miri))] // miri does not currently support this call + { + if let Ok(file) = file.canonicalize() { + return Some(file); } - - Path::new(self.manifest_dir) - .ancestors() - .find_map(|ancestor| { - let path = ancestor.join(file); - if path.exists() { - Some(path) - } else { - None - } - }) } + + Path::new(self.manifest_dir) + .ancestors() + .find_map(|ancestor| { + let path = ancestor.join(file); + if path.exists() { + Some(path) + } else { + None + } + }) } + #[cfg(kani)] pub fn work_dir(&self) -> Option { - #[cfg(kani)] - { - None - } - - #[cfg(not(kani))] - { - let mut work_dir = self.abs_path()?; - work_dir.pop(); + None + } - if !self.is_harnessed() { - return Some(work_dir); - } + #[cfg(not(kani))] + pub fn work_dir(&self) -> Option { + let mut work_dir = self.abs_path()?; + work_dir.pop(); - work_dir.push("__fuzz__"); - if let Some(test_name) = self.test_name.as_ref() { - work_dir.push(test_name); - } else { - work_dir.push(self.fuzz_dir()); - } + if !self.is_harnessed() { + return Some(work_dir); + } - Some(work_dir) + work_dir.push("__fuzz__"); + if let Some(test_name) = self.test_name.as_ref() { + work_dir.push(test_name); + } else { + work_dir.push(self.fuzz_dir()); } + + Some(work_dir) } + #[cfg(kani)] pub fn is_harnessed(&self) -> bool { - #[cfg(kani)] - { - false - } + false + } - #[cfg(not(kani))] - { - is_harnessed(self.item_path) - } + #[cfg(not(kani))] + pub fn is_harnessed(&self) -> bool { + is_harnessed(self.item_path) } fn fuzz_dir(&self) -> String {