Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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: 4 additions & 0 deletions src/librustc_mir/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl NonConstOp for IfOrMatch {
}
}

#[derive(Debug)]
pub struct InlineAsm;
impl NonConstOp for InlineAsm {}

#[derive(Debug)]
pub struct LiveDrop;
impl NonConstOp for LiveDrop {
Expand Down
30 changes: 25 additions & 5 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,22 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
StatementKind::Assign(..) | StatementKind::SetDiscriminant { .. } => {
self.super_statement(statement, location);
}
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {

StatementKind::FakeRead(
FakeReadCause::ForMatchedPlace
| FakeReadCause::ForMatchGuard
| FakeReadCause::ForGuardBinding,
_,
) => {
self.check_op(ops::IfOrMatch);
}
// FIXME(eddyb) should these really do nothing?
StatementKind::FakeRead(..)
StatementKind::LlvmInlineAsm { .. } => {
self.check_op(ops::InlineAsm);
}

StatementKind::FakeRead(FakeReadCause::ForLet | FakeReadCause::ForIndex, _)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::LlvmInlineAsm { .. }
| StatementKind::Retag { .. }
| StatementKind::AscribeUserType(..)
| StatementKind::Nop => {}
Expand Down Expand Up @@ -572,7 +580,19 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
}
}

_ => {}
// FIXME: Some of these are only caught by `min_const_fn`, but should error here
// instead.
TerminatorKind::Abort
| TerminatorKind::Assert { .. }
| TerminatorKind::FalseEdges { .. }
| TerminatorKind::FalseUnwind { .. }
| TerminatorKind::GeneratorDrop
| TerminatorKind::Goto { .. }
| TerminatorKind::Resume
| TerminatorKind::Return
| TerminatorKind::SwitchInt { .. }
| TerminatorKind::Unreachable
| TerminatorKind::Yield { .. } => {}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/consts/inline_asm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![feature(llvm_asm)]

const _: () = unsafe { llvm_asm!("nop") };
//~^ ERROR contains unimplemented expression type

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/consts/inline_asm.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0019]: constant contains unimplemented expression type
--> $DIR/inline_asm.rs:3:1
|
LL | const _: () = unsafe { llvm_asm!("nop") };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0019`.
2 changes: 1 addition & 1 deletion src/test/ui/consts/miri_unleashed/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
fn main() {}

// Make sure we catch executing inline assembly.
static TEST_BAD: () = {
static TEST_BAD: () = { //~ WARN: skipping const checks
unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
//~^ ERROR could not evaluate static initializer
//~| NOTE in this expansion of llvm_asm!
Expand Down
13 changes: 12 additions & 1 deletion src/test/ui/consts/miri_unleashed/inline_asm.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
warning: skipping const checks
--> $DIR/inline_asm.rs:9:1
|
LL | / static TEST_BAD: () = {
LL | | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
LL | |
LL | |
LL | |
LL | | };
| |__^

error[E0080]: could not evaluate static initializer
--> $DIR/inline_asm.rs:10:14
|
Expand All @@ -6,6 +17,6 @@ LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error
error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0080`.