-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(call_graph): Emit warnings when encountering foreign calls
- Loading branch information
1 parent
8552c02
commit a363771
Showing
7 changed files
with
128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ print-call-graph | ||
//@ stderr: empty | ||
|
||
use std::alloc::Layout; | ||
|
||
fn make_allocator_intrinsics_call() { | ||
let _ = unsafe { std::alloc::alloc(Layout::from_size_align_unchecked(8, 8)) }; | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
make_allocator_intrinsics_call(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ print-call-graph | ||
//@ stderr: empty | ||
|
||
#![allow(internal_features)] | ||
#![feature(core_intrinsics)] | ||
|
||
fn make_intrinsics_call() { | ||
let _ = core::intrinsics::caller_location(); | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
make_intrinsics_call(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//@ print-call-graph | ||
//@ print-targets | ||
//@ stdout | ||
//@ stderr | ||
|
||
extern "C" { | ||
fn foreign(); | ||
} | ||
|
||
unsafe extern "C" fn not_foreign() {} | ||
|
||
fn make_extern_calls() { | ||
unsafe { foreign() }; | ||
unsafe { not_foreign() }; | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
make_extern_calls(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
warning: encountered foreign call during call graph construction | ||
--> tests/ui/call_graph/warn_on_foreign_calls.rs:13:14 | ||
| | ||
13 | unsafe { foreign() }; | ||
| ^^^^^^^^^ call to foreign | ||
| | ||
= note: in make_extern_calls | ||
|
||
warning: 1 warning emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
@@@ call graph @@@ | ||
|
||
entry points: | ||
|
||
test test | ||
-> make_extern_calls at tests/ui/call_graph/warn_on_foreign_calls.rs:12:1: 12:23 (#0) | ||
|
||
nested calls at distance 1: | ||
|
||
make_extern_calls at tests/ui/call_graph/warn_on_foreign_calls.rs:12:1: 12:23 (#0) | ||
-> foreign at tests/ui/call_graph/warn_on_foreign_calls.rs:7:5: 7:17 (#0) | ||
-> not_foreign at tests/ui/call_graph/warn_on_foreign_calls.rs:10:1: 10:35 (#0) | ||
|
||
nested calls at distance 2: | ||
|
||
|
||
@@@ targets @@@ | ||
|
||
tests -(1)-> [unsafe] not_foreign at tests/ui/call_graph/warn_on_foreign_calls.rs:10:1: 10:35 (#0) | ||
(1) [tainted] test | ||
|
||
tests -(0)-> [unsafe] make_extern_calls at tests/ui/call_graph/warn_on_foreign_calls.rs:12:1: 12:23 (#0) | ||
(0) test | ||
|
||
targets: 2 total; 0 safe; 2 unsafe (0 tainted) |