forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#85306 - LeSeulArtichaut:thir-unsafeck, r=ni…
…komatsakis Add DerefOfRawPointer and CallToFunctionWith to THIR unsafeck Extends THIR unsafeck to check for two more cases of unsafe operations: dereferences of raw pointers and calls to functions with `#[target_feature]` (RFC 2396). The check for the latter is pretty much copy-pasted from the existing MIR equivalent. This will clash with rust-lang#83842 and rust-lang#85273 which are arguably more important, let's maybe focus on getting those merged first, this can wait. r? `@nikomatsakis` cc rust-lang/project-thir-unsafeck#7
- Loading branch information
Showing
30 changed files
with
260 additions
and
25 deletions.
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
2 changes: 1 addition & 1 deletion
2
...or/issue-45729-unsafe-in-generator.stderr → ...ssue-45729-unsafe-in-generator.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
|
||
#![feature(generators)] | ||
|
||
fn main() { | ||
|
11 changes: 11 additions & 0 deletions
11
src/test/ui/generator/issue-45729-unsafe-in-generator.thir.stderr
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,11 @@ | ||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block | ||
--> $DIR/issue-45729-unsafe-in-generator.rs:8:9 | ||
| | ||
LL | *(1 as *mut u32) = 42; | ||
| ^^^^^^^^^^^^^^^^ dereference of raw pointer | ||
| | ||
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
4 changes: 2 additions & 2 deletions
4
src/test/ui/issues/issue-47412.stderr → src/test/ui/issues/issue-47412.mir.stderr
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,11 @@ | ||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block | ||
--> $DIR/issue-47412.rs:21:11 | ||
| | ||
LL | match *ptr {} | ||
| ^^^^ dereference of raw pointer | ||
| | ||
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
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
2 changes: 2 additions & 0 deletions
2
src/test/ui/rfcs/rfc-2396-target_feature-11/closures-inherit-target_feature.rs
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
2 changes: 1 addition & 1 deletion
2
.../rfc-2396-target_feature-11/fn-ptr.stderr → ...-2396-target_feature-11/fn-ptr.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
18 changes: 18 additions & 0 deletions
18
src/test/ui/rfcs/rfc-2396-target_feature-11/fn-ptr.thir.stderr
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,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/fn-ptr.rs:11:21 | ||
| | ||
LL | #[target_feature(enable = "sse2")] | ||
| ---------------------------------- `#[target_feature]` added here | ||
... | ||
LL | let foo: fn() = foo; | ||
| ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected fn pointer `fn()` | ||
found fn item `fn() {foo}` | ||
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
20 changes: 10 additions & 10 deletions
20
...-2396-target_feature-11/safe-calls.stderr → ...6-target_feature-11/safe-calls.mir.stderr
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// revisions: mir thir | ||
// [thir]compile-flags: -Z thir-unsafeck | ||
// only-x86_64 | ||
|
||
#![feature(target_feature_11)] | ||
|
83 changes: 83 additions & 0 deletions
83
src/test/ui/rfcs/rfc-2396-target_feature-11/safe-calls.thir.stderr
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,83 @@ | ||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:23:5 | ||
| | ||
LL | sse2(); | ||
| ^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:24:5 | ||
| | ||
LL | avx_bmi2(); | ||
| ^^^^^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:25:5 | ||
| | ||
LL | Quux.avx_bmi2(); | ||
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:30:5 | ||
| | ||
LL | avx_bmi2(); | ||
| ^^^^^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:31:5 | ||
| | ||
LL | Quux.avx_bmi2(); | ||
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:36:5 | ||
| | ||
LL | sse2(); | ||
| ^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:37:5 | ||
| | ||
LL | avx_bmi2(); | ||
| ^^^^^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:38:5 | ||
| | ||
LL | Quux.avx_bmi2(); | ||
| ^^^^^^^^^^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:44:5 | ||
| | ||
LL | sse2(); | ||
| ^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error[E0133]: call to function with `#[target_feature]` is unsafe and requires unsafe function or block | ||
--> $DIR/safe-calls.rs:47:18 | ||
| | ||
LL | const name: () = sse2(); | ||
| ^^^^^^ call to function with `#[target_feature]` | ||
| | ||
= note: can only be called if the required target features are available | ||
|
||
error: aborting due to 10 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0133`. |
Oops, something went wrong.