Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set LLVM Flag to Disable cmov (select instr) generation #380

Merged
merged 8 commits into from
Aug 7, 2024
8 changes: 8 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ pub struct BuildOptions {
/// the `*-trace-compares` instrumentation assumes that the instruction is
/// available.
pub no_trace_compares: bool,

#[arg(long)]
/// Disable transformation of if-statements into `cmov` instructions (when this
/// happens, we get no coverage feedback for that branch). Default setting is true.
/// A further explanation can be found here:
/// https://github.com/rust-fuzz/cargo-fuzz/pull/380#issue-2445529059
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's inline the explanation here. It will be more likely to be kept up to date that way, and user's won't have to chase hyperlinks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the latest commit; I've condensed it as much as I can, but it's definitely a long doc comment.

pub disable_branch_folding: Option<bool>,
}

impl stdfmt::Display for BuildOptions {
Expand Down Expand Up @@ -233,6 +240,7 @@ mod test {
strip_dead_code: false,
no_cfg_fuzzing: false,
no_trace_compares: false,
disable_branch_folding: None,
};

let opts = vec![
Expand Down
4 changes: 4 additions & 0 deletions src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ impl FuzzProject {
rustflags.push_str(" -Cllvm-args=-sanitizer-coverage-trace-compares");
}

if build.disable_branch_folding.unwrap_or(true) {
rustflags.push_str(" -Cllvm-args=-simplifycfg-branch-fold-threshold=0");
}

if !build.no_cfg_fuzzing {
rustflags.push_str(" --cfg fuzzing");
}
Expand Down