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

Rust: Allow SSA and some data flow for mutable borrows #18872

Merged
merged 6 commits into from
Mar 4, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Rust: Reorganize pointers tests and add additional tests
  • Loading branch information
paldepind committed Feb 26, 2025
commit 51ae7c6b8ce764f2baa1bae14eaf7cfa9a55fe8e
35 changes: 5 additions & 30 deletions rust/ql/test/library-tests/dataflow/global/main.rs
Original file line number Diff line number Diff line change
@@ -64,19 +64,19 @@ struct MyFlag {
}

impl MyFlag {
fn data_in(&self, n: i64) {
fn data_in(self, n: i64) {
sink(n); // $ hasValueFlow=1 hasValueFlow=8
}

fn get_data(&self) -> i64 {
fn get_data(self) -> i64 {
if self.flag {
0
} else {
source(2)
}
}

fn data_through(&self, n: i64) -> i64 {
fn data_through(self, n: i64) -> i64 {
if self.flag {
0
} else {
@@ -107,13 +107,13 @@ fn data_through_method() {
fn data_in_to_method_called_as_function() {
let mn = MyFlag { flag: true };
let a = source(8);
MyFlag::data_in(&mn, a);
MyFlag::data_in(mn, a);
}

fn data_through_method_called_as_function() {
let mn = MyFlag { flag: true };
let a = source(12);
let b = MyFlag::data_through(&mn, a);
let b = MyFlag::data_through(mn, a);
sink(b); // $ hasValueFlow=12
}

@@ -223,29 +223,6 @@ fn test_async_await() {
futures::executor::block_on(test_async_await_async_part());
}

// Flow out of mutable parameters.

fn set_int(n: &mut i64, c: i64) {
*n = c;
}

fn mutates_argument_1() {
// Passing an already borrowed value to a function and then reading from the same borrow.
let mut n = 0;
let m = &mut n;
sink(*m);
set_int(m, source(37));
sink(*m); // $ hasValueFlow=37
}

fn mutates_argument_2() {
// Borrowing at the call and then reading from the unborrowed variable.
let mut n = 0;
sink(n);
set_int(&mut n, source(88));
sink(n); // $ MISSING: hasValueFlow=88
}

fn main() {
data_out_of_call();
data_in_to_call();
@@ -258,6 +235,4 @@ fn main() {

test_operator_overloading();
test_async_await();
mutates_argument_1();
mutates_argument_2();
}
Loading
Oops, something went wrong.