Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for inline assembly in THIR unsafeck #85259

Merged
merged 2 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_mir_build/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
_ => {}
}

Expand Down Expand Up @@ -194,7 +197,6 @@ impl BodyUnsafety {
#[derive(Clone, Copy, PartialEq)]
enum UnsafeOpKind {
CallToUnsafeFunction,
#[allow(dead_code)] // FIXME
UseOfInlineAssembly,
#[allow(dead_code)] // FIXME
InitializingTypeWith,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0472]: inline assembly is unsupported on this target
--> $DIR/bad-arch.rs:20:9
--> $DIR/bad-arch.rs:22:9
|
LL | asm!("");
| ^^^^^^^^^

error[E0472]: inline assembly is unsupported on this target
--> $DIR/bad-arch.rs:25:1
--> $DIR/bad-arch.rs:27:1
|
LL | global_asm!("");
| ^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/asm/bad-arch.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// compile-flags: --target sparc-unknown-linux-gnu
// needs-llvm-components: sparc
// revisions: mirunsafeck thirunsafeck
// [thirunsafeck]compile-flags: -Z thir-unsafeck

#![feature(no_core, lang_items, rustc_attrs)]
#![no_core]
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/asm/bad-arch.thirunsafeck.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error[E0472]: inline assembly is unsupported on this target
--> $DIR/bad-arch.rs:22:9
|
LL | asm!("");
| ^^^^^^^^^

error[E0472]: inline assembly is unsupported on this target
--> $DIR/bad-arch.rs:27:1
|
LL | global_asm!("");
| ^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `global_asm` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:8:15
--> $DIR/bad-template.rs:10:15
|
LL | asm!("{}");
| ^^ from here
|
= note: no arguments were given

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:10:15
--> $DIR/bad-template.rs:12:15
|
LL | asm!("{1}", in(reg) foo);
| ^^^ from here
|
= note: there is 1 argument

error: argument never used
--> $DIR/bad-template.rs:10:21
--> $DIR/bad-template.rs:12:21
|
LL | asm!("{1}", in(reg) foo);
| ^^^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`

error: there is no argument named `a`
--> $DIR/bad-template.rs:13:15
--> $DIR/bad-template.rs:15:15
|
LL | asm!("{a}");
| ^^^

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:15:15
--> $DIR/bad-template.rs:17:15
|
LL | asm!("{}", a = in(reg) foo);
| ^^ --------------- named argument
Expand All @@ -38,37 +38,37 @@ LL | asm!("{}", a = in(reg) foo);
|
= note: no positional arguments were given
note: named arguments cannot be referenced by position
--> $DIR/bad-template.rs:15:20
--> $DIR/bad-template.rs:17:20
|
LL | asm!("{}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^

error: named argument never used
--> $DIR/bad-template.rs:15:20
--> $DIR/bad-template.rs:17:20
|
LL | asm!("{}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:18:15
--> $DIR/bad-template.rs:20:15
|
LL | asm!("{1}", a = in(reg) foo);
| ^^^ from here
|
= note: no positional arguments were given

error: named argument never used
--> $DIR/bad-template.rs:18:21
--> $DIR/bad-template.rs:20:21
|
LL | asm!("{1}", a = in(reg) foo);
| ^^^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:21:15
--> $DIR/bad-template.rs:23:15
|
LL | asm!("{}", in("eax") foo);
| ^^ ------------- explicit register argument
Expand All @@ -77,19 +77,19 @@ LL | asm!("{}", in("eax") foo);
|
= note: no positional arguments were given
note: explicit register arguments cannot be used in the asm template
--> $DIR/bad-template.rs:21:20
--> $DIR/bad-template.rs:23:20
|
LL | asm!("{}", in("eax") foo);
| ^^^^^^^^^^^^^

error: asm template modifier must be a single character
--> $DIR/bad-template.rs:23:17
--> $DIR/bad-template.rs:25:17
|
LL | asm!("{:foo}", in(reg) foo);
| ^^^

error: multiple unused asm arguments
--> $DIR/bad-template.rs:25:18
--> $DIR/bad-template.rs:27:18
|
LL | asm!("", in(reg) 0, in(reg) 1);
| ^^^^^^^^^ ^^^^^^^^^ argument never used
Expand All @@ -99,37 +99,37 @@ LL | asm!("", in(reg) 0, in(reg) 1);
= help: if these arguments are intentionally unused, consider using them in an asm comment: `"/* {0} {1} */"`

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:31:14
--> $DIR/bad-template.rs:33:14
|
LL | global_asm!("{}");
| ^^ from here
|
= note: no arguments were given

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:33:14
--> $DIR/bad-template.rs:35:14
|
LL | global_asm!("{1}", const FOO);
| ^^^ from here
|
= note: there is 1 argument

error: argument never used
--> $DIR/bad-template.rs:33:20
--> $DIR/bad-template.rs:35:20
|
LL | global_asm!("{1}", const FOO);
| ^^^^^^^^^ argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {0} */"`

error: there is no argument named `a`
--> $DIR/bad-template.rs:36:14
--> $DIR/bad-template.rs:38:14
|
LL | global_asm!("{a}");
| ^^^

error: invalid reference to argument at index 0
--> $DIR/bad-template.rs:38:14
--> $DIR/bad-template.rs:40:14
|
LL | global_asm!("{}", a = const FOO);
| ^^ ------------- named argument
Expand All @@ -138,43 +138,43 @@ LL | global_asm!("{}", a = const FOO);
|
= note: no positional arguments were given
note: named arguments cannot be referenced by position
--> $DIR/bad-template.rs:38:19
--> $DIR/bad-template.rs:40:19
|
LL | global_asm!("{}", a = const FOO);
| ^^^^^^^^^^^^^

error: named argument never used
--> $DIR/bad-template.rs:38:19
--> $DIR/bad-template.rs:40:19
|
LL | global_asm!("{}", a = const FOO);
| ^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: invalid reference to argument at index 1
--> $DIR/bad-template.rs:41:14
--> $DIR/bad-template.rs:43:14
|
LL | global_asm!("{1}", a = const FOO);
| ^^^ from here
|
= note: no positional arguments were given

error: named argument never used
--> $DIR/bad-template.rs:41:20
--> $DIR/bad-template.rs:43:20
|
LL | global_asm!("{1}", a = const FOO);
| ^^^^^^^^^^^^^ named argument never used
|
= help: if this argument is intentionally unused, consider using it in an asm comment: `"/* {a} */"`

error: asm template modifier must be a single character
--> $DIR/bad-template.rs:44:16
--> $DIR/bad-template.rs:46:16
|
LL | global_asm!("{:foo}", const FOO);
| ^^^

error: multiple unused asm arguments
--> $DIR/bad-template.rs:46:17
--> $DIR/bad-template.rs:48:17
|
LL | global_asm!("", const FOO, const FOO);
| ^^^^^^^^^ ^^^^^^^^^ argument never used
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/asm/bad-template.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// only-x86_64
// revisions: mirunsafeck thirunsafeck
// [thirunsafeck]compile-flags: -Z thir-unsafeck

#![feature(asm, global_asm)]

Expand Down
Loading