Check for inline assembly in THIR unsafeck
This commit is contained in:
parent
36a4d14c7e
commit
116bc6dd76
@ -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,
|
||||
|
20
src/test/ui/unsafe/inline_asm.mir.stderr
Normal file
20
src/test/ui/unsafe/inline_asm.mir.stderr
Normal 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`.
|
10
src/test/ui/unsafe/inline_asm.rs
Normal file
10
src/test/ui/unsafe/inline_asm.rs
Normal 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
|
||||
}
|
20
src/test/ui/unsafe/inline_asm.thir.stderr
Normal file
20
src/test/ui/unsafe/inline_asm.thir.stderr
Normal 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`.
|
Loading…
x
Reference in New Issue
Block a user