Check for raw pointer dereference in THIR unsafeck
This commit is contained in:
parent
f94942d842
commit
27fe959c2c
@ -153,6 +153,11 @@ fn visit_expr(&mut self, expr: &Expr<'tcx>) {
|
||||
ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => {
|
||||
self.requires_unsafe(expr.span, UseOfInlineAssembly);
|
||||
}
|
||||
ExprKind::Deref { arg } => {
|
||||
if self.thir[arg].ty.is_unsafe_ptr() {
|
||||
self.requires_unsafe(expr.span, DerefOfRawPointer);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -203,7 +208,6 @@ enum UnsafeOpKind {
|
||||
UseOfMutableStatic,
|
||||
#[allow(dead_code)] // FIXME
|
||||
UseOfExternStatic,
|
||||
#[allow(dead_code)] // FIXME
|
||||
DerefOfRawPointer,
|
||||
#[allow(dead_code)] // FIXME
|
||||
AssignToDroppingUnionField,
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/issue-45729-unsafe-in-generator.rs:5:9
|
||||
--> $DIR/issue-45729-unsafe-in-generator.rs:8:9
|
||||
|
|
||||
LL | *(1 as *mut u32) = 42;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer
|
@ -1,3 +1,6 @@
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
#![feature(generators)]
|
||||
|
||||
fn main() {
|
||||
|
@ -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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: access to union field is unsafe and requires unsafe function or block
|
||||
--> $DIR/issue-47412.rs:11:11
|
||||
--> $DIR/issue-47412.rs:14:11
|
||||
|
|
||||
LL | match u.void {}
|
||||
| ^^^^^^ access to union field
|
||||
@ -7,7 +7,7 @@ LL | match u.void {}
|
||||
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
|
||||
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/issue-47412.rs:17:11
|
||||
--> $DIR/issue-47412.rs:21:11
|
||||
|
|
||||
LL | match *ptr {}
|
||||
| ^^^^ dereference of raw pointer
|
@ -1,3 +1,6 @@
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
enum Void {}
|
||||
|
||||
@ -9,7 +12,8 @@ fn union_field() {
|
||||
union Union { unit: (), void: Void }
|
||||
let u = Union { unit: () };
|
||||
match u.void {}
|
||||
//~^ ERROR access to union field is unsafe
|
||||
//[mir]~^ ERROR access to union field is unsafe
|
||||
// FIXME(thir-unsafeck): AccessToUnionField unimplemented
|
||||
}
|
||||
|
||||
fn raw_ptr_deref() {
|
||||
|
11
src/test/ui/issues/issue-47412.thir.stderr
Normal file
11
src/test/ui/issues/issue-47412.thir.stderr
Normal file
@ -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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/safety-fn-body.rs:11:9
|
||||
--> $DIR/safety-fn-body.rs:14:9
|
||||
|
|
||||
LL | *self += 1;
|
||||
| ^^^^^^^^^^ dereference of raw pointer
|
@ -1,6 +1,9 @@
|
||||
// Check that an unsafe impl does not imply that unsafe actions are
|
||||
// legal in the methods.
|
||||
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
unsafe trait UnsafeTrait : Sized {
|
||||
fn foo(self) { }
|
||||
}
|
||||
|
11
src/test/ui/traits/safety-fn-body.thir.stderr
Normal file
11
src/test/ui/traits/safety-fn-body.thir.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/safety-fn-body.rs:14:9
|
||||
|
|
||||
LL | *self += 1;
|
||||
| ^^^^^ 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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/issue-45087-unreachable-unsafe.rs:3:5
|
||||
--> $DIR/issue-45087-unreachable-unsafe.rs:6:5
|
||||
|
|
||||
LL | *(1 as *mut u32) = 42;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ dereference of raw pointer
|
@ -1,3 +1,6 @@
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
fn main() {
|
||||
return;
|
||||
*(1 as *mut u32) = 42;
|
||||
|
@ -0,0 +1,11 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/issue-45087-unreachable-unsafe.rs:6:5
|
||||
|
|
||||
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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-fn-assign-deref-ptr.rs:2:5
|
||||
--> $DIR/unsafe-fn-assign-deref-ptr.rs:5:5
|
||||
|
|
||||
LL | *p = 0;
|
||||
| ^^^^^^ dereference of raw pointer
|
@ -1,3 +1,6 @@
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
fn f(p: *mut u8) {
|
||||
*p = 0; //~ ERROR dereference of raw pointer is unsafe
|
||||
return;
|
||||
|
11
src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr
Normal file
11
src/test/ui/unsafe/unsafe-fn-assign-deref-ptr.thir.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-fn-assign-deref-ptr.rs:5:5
|
||||
|
|
||||
LL | *p = 0;
|
||||
| ^^ 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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-fn-deref-ptr.rs:2:12
|
||||
--> $DIR/unsafe-fn-deref-ptr.rs:5:12
|
||||
|
|
||||
LL | return *p;
|
||||
| ^^ dereference of raw pointer
|
@ -1,3 +1,6 @@
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
fn f(p: *const u8) -> u8 {
|
||||
return *p; //~ ERROR dereference of raw pointer is unsafe
|
||||
}
|
||||
|
11
src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr
Normal file
11
src/test/ui/unsafe/unsafe-fn-deref-ptr.thir.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-fn-deref-ptr.rs:5:12
|
||||
|
|
||||
LL | return *p;
|
||||
| ^^ 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`.
|
@ -1,5 +1,5 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:8:5
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:11:5
|
||||
|
|
||||
LL | *a == b
|
||||
| ^^ dereference of raw pointer
|
@ -1,3 +1,6 @@
|
||||
// revisions: mir thir
|
||||
// [thir]compile-flags: -Z thir-unsafeck
|
||||
|
||||
#![stable(feature = "foo", since = "1.33.0")]
|
||||
#![feature(staged_api)]
|
||||
#![feature(const_raw_ptr_deref)]
|
||||
|
11
src/test/ui/unsafe/unsafe-unstable-const-fn.thir.stderr
Normal file
11
src/test/ui/unsafe/unsafe-unstable-const-fn.thir.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
|
||||
--> $DIR/unsafe-unstable-const-fn.rs:11:5
|
||||
|
|
||||
LL | *a == b
|
||||
| ^^ 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`.
|
Loading…
Reference in New Issue
Block a user