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

Analyze unsafe code reachability #3546

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

celinval
Copy link
Contributor

Add call graph analysis to scanner in order to find the distance between functions in a crate and unsafe functions.

For that, we build the crate call graph and collect the unsafe functions. After that, do reverse BFS traversal from the unsafe functions and store the distance to other functions. The result is stored in a new csv file.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@celinval celinval requested a review from a team as a code owner September 24, 2024 14:47
@github-actions github-actions bot added the Z-BenchCI Tag a PR to run benchmark CI label Sep 24, 2024
Add callgraph analysis to scanner in order to find the distance between
functions in a crate and unsafe functions.

For that, we build the crate call graph and collect the unsafe
functions. After that, do reverse BFS traversal from the unsafe
functions and store the distance to other functions.
The result is stored in a new csv file.
stable_mir = { path = "<path_to_rustc>/stable_mir", optional = true }

[features]
clion = ['rustc_smir', 'stable_mir']
Copy link
Member

Choose a reason for hiding this comment

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

How are the changes in this file related to what the PR description says?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I already removed them... They are not. :)

@@ -104,7 +105,7 @@ for f in $results/*overall.csv; do
fname=$(basename $f)
crate=${fname%_scan_overall.csv}
echo -n "$crate," >> $summary
tr -d [:alpha:]_,; < $f | tr -s '\n' ',' \
tr -d "[:alpha:]_,;" < $f | tr -s '\n' ',' \
Copy link
Member

Choose a reason for hiding this comment

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

Thank you, but how did this ever work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it was a typo when I created the script from my local script. This script doesn't run as part of the CI, which is probably something that we need to address.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, would love for that to be in CI in some way or other!

Comment on lines +110 to +117

extern "C" {
fn external_function();
}

pub fn call_external() {
unsafe { external_function() };
}
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps those various functions could have comments explaining why they are there?

// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! Provide different static analysis to be performed in the call graph
Copy link
Member

Choose a reason for hiding this comment

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

What does "different" mean here?

Copy link
Contributor Author

@celinval celinval Sep 24, 2024

Choose a reason for hiding this comment

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

Let me improve this... but I think what I wanted to express is that this module is for inter-function analysis while the other module is for intra-function analysis.

Comment on lines +254 to +258
pub const fn num_props() -> usize {
[$(stringify!($prop),)+].len()
}

fn new(fn_name: String) -> Self {
pub fn new(fn_name: String) -> Self {
Copy link
Member

Choose a reason for hiding this comment

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

Why are those newly public? Probably just a lack of understanding on my part, but I couldn't spot a new use of them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I was using them in the call_graph module, but I can double check if that is still needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-BenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants