Check for inline assembly in THIR unsafeck

This commit is contained in:
Smitty 2021-05-13 10:20:51 -04:00
parent 36a4d14c7e
commit 116bc6dd76
4 changed files with 53 additions and 1 deletions

View File

@ -153,6 +153,9 @@ impl<'thir, 'tcx> Visitor<'thir, 'tcx> for UnsafetyVisitor<'tcx> {
self.requires_unsafe(expr.span, CallToUnsafeFunction);
}
}
ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => {
self.requires_unsafe(expr.span, UseOfInlineAssembly);
}
_ => {}
}
@ -194,7 +197,6 @@ impl BodyUnsafety {
#[derive(Clone, Copy, PartialEq)]
enum UnsafeOpKind {
CallToUnsafeFunction,
#[allow(dead_code)] // FIXME
UseOfInlineAssembly,
#[allow(dead_code)] // FIXME
InitializingTypeWith,

View File

@ -0,0 +1,20 @@
error[E0133]: use of inline assembly is unsafe and requires unsafe function or block
--> $DIR/inline_asm.rs:8:5
|
LL | asm!("nop");
| ^^^^^^^^^^^^ use of inline assembly
|
= note: inline assembly is entirely unchecked and can cause undefined behavior
error[E0133]: use of inline assembly is unsafe and requires unsafe function or block
--> $DIR/inline_asm.rs:9:5
|
LL | llvm_asm!("nop");
| ^^^^^^^^^^^^^^^^^ use of inline assembly
|
= note: inline assembly is entirely unchecked and can cause undefined behavior
= note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0133`.

View File

@ -0,0 +1,10 @@
// revisions: mir thir
// [thir]compile-flags: -Z thir-unsafeck
#![feature(llvm_asm)]
#![feature(asm)]
fn main() {
asm!("nop"); //~ ERROR use of inline assembly is unsafe and requires unsafe function or block
llvm_asm!("nop"); //~ ERROR use of inline assembly is unsafe and requires unsafe function or block
}

View File

@ -0,0 +1,20 @@
error[E0133]: use of inline assembly is unsafe and requires unsafe function or block
--> $DIR/inline_asm.rs:8:5
|
LL | asm!("nop");
| ^^^^^^^^^^^^ use of inline assembly
|
= note: inline assembly is entirely unchecked and can cause undefined behavior
error[E0133]: use of inline assembly is unsafe and requires unsafe function or block
--> $DIR/inline_asm.rs:9:5
|
LL | llvm_asm!("nop");
| ^^^^^^^^^^^^^^^^^ use of inline assembly
|
= note: inline assembly is entirely unchecked and can cause undefined behavior
= note: this error originates in the macro `llvm_asm` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0133`.