Reformat mir! macro invocations to use braces.

The `mir!` macro has multiple parts:
- An optional return type annotation.
- A sequence of zero or more local declarations.
- A mandatory starting anonymous basic block, which is brace-delimited.
- A sequence of zero of more additional named basic blocks.

Some `mir!` invocations use braces with a "block" style, like so:
```
mir! {
    let _unit: ();
    {
	let non_copy = S(42);
	let ptr = std::ptr::addr_of_mut!(non_copy);
	// Inside `callee`, the first argument and `*ptr` are basically
	// aliasing places!
	Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue())
    }
    after_call = {
	Return()
    }
}
```
Some invocations use parens with a "block" style, like so:
```
mir!(
    let x: [i32; 2];
    let one: i32;
    {
	x = [42, 43];
	one = 1;
	x = [one, 2];
	RET = Move(x);
	Return()
    }
)
```
And some invocations uses parens with a "tighter" style, like so:
```
mir!({
    SetDiscriminant(*b, 0);
    Return()
})
```
This last style is generally used for cases where just the mandatory
starting basic block is present. Its braces are placed next to the
parens.

This commit changes all `mir!` invocations to use braces with a "block"
style. Why?

- Consistency is good.

- The contents of the invocation is a block of code, so it's odd to use
  parens. They are more normally used for function-like macros.

- Most importantly, the next commit will enable rustfmt for
  `tests/mir-opt/`. rustfmt is more aggressive about formatting macros
  that use parens than macros that use braces. Without this commit's
  changes, rustfmt would break a couple of `mir!` macro invocations that
  use braces within `tests/mir-opt` by inserting an extraneous comma.
  E.g.:
  ```
  mir!(type RET = (i32, bool);, { // extraneous comma after ';'
      RET.0 = 1;
      RET.1 = true;
      Return()
  })
  ```
  Switching those `mir!` invocations to use braces avoids that problem,
  resulting in this, which is nicer to read as well as being valid
  syntax:
  ```
  mir! {
      type RET = (i32, bool);
      {
	  RET.0 = 1;
	  RET.1 = true;
	  Return()
      }
  }
  ```
This commit is contained in:
Nicholas Nethercote 2024-06-03 10:19:57 +10:00
parent a6416d8907
commit ac24299636
52 changed files with 379 additions and 327 deletions

View File

@ -34,14 +34,14 @@ use std::fmt;
/// ///
/// ```text /// ```text
// fn drop_term<T>(t: &mut T) { // fn drop_term<T>(t: &mut T) {
// mir!( // mir! {
// { // {
// Drop(*t, exit) // Drop(*t, exit)
// } // }
// exit = { // exit = {
// Return() // Return()
// } // }
// ) // }
// } // }
/// ``` /// ```
pub struct ElaborateDrops; pub struct ElaborateDrops;

View File

@ -20,7 +20,7 @@
//! //!
//! #[custom_mir(dialect = "built")] //! #[custom_mir(dialect = "built")]
//! pub fn simple(x: i32) -> i32 { //! pub fn simple(x: i32) -> i32 {
//! mir!( //! mir! {
//! let temp2: i32; //! let temp2: i32;
//! //!
//! { //! {
@ -33,7 +33,7 @@
//! RET = temp2; //! RET = temp2;
//! Return() //! Return()
//! } //! }
//! ) //! }
//! } //! }
//! ``` //! ```
//! //!
@ -71,7 +71,7 @@
//! //!
//! #[custom_mir(dialect = "built")] //! #[custom_mir(dialect = "built")]
//! pub fn choose_load(a: &i32, b: &i32, c: bool) -> i32 { //! pub fn choose_load(a: &i32, b: &i32, c: bool) -> i32 {
//! mir!( //! mir! {
//! { //! {
//! match c { //! match c {
//! true => t, //! true => t,
@ -93,20 +93,22 @@
//! RET = *temp; //! RET = *temp;
//! Return() //! Return()
//! } //! }
//! ) //! }
//! } //! }
//! //!
//! #[custom_mir(dialect = "built")] //! #[custom_mir(dialect = "built")]
//! fn unwrap_unchecked<T>(opt: Option<T>) -> T { //! fn unwrap_unchecked<T>(opt: Option<T>) -> T {
//! mir!({ //! mir! {
//! RET = Move(Field(Variant(opt, 1), 0)); //! {
//! Return() //! RET = Move(Field(Variant(opt, 1), 0));
//! }) //! Return()
//! }
//! }
//! } //! }
//! //!
//! #[custom_mir(dialect = "runtime", phase = "optimized")] //! #[custom_mir(dialect = "runtime", phase = "optimized")]
//! fn push_and_pop<T>(v: &mut Vec<T>, value: T) { //! fn push_and_pop<T>(v: &mut Vec<T>, value: T) {
//! mir!( //! mir! {
//! let _unused; //! let _unused;
//! let popped; //! let popped;
//! //!
@ -125,19 +127,19 @@
//! ret = { //! ret = {
//! Return() //! Return()
//! } //! }
//! ) //! }
//! } //! }
//! //!
//! #[custom_mir(dialect = "runtime", phase = "optimized")] //! #[custom_mir(dialect = "runtime", phase = "optimized")]
//! fn annotated_return_type() -> (i32, bool) { //! fn annotated_return_type() -> (i32, bool) {
//! mir!( //! mir! {
//! type RET = (i32, bool); //! type RET = (i32, bool);
//! { //! {
//! RET.0 = 1; //! RET.0 = 1;
//! RET.1 = true; //! RET.1 = true;
//! Return() //! Return()
//! } //! }
//! ) //! }
//! } //! }
//! ``` //! ```
//! //!
@ -152,7 +154,7 @@
//! //!
//! #[custom_mir(dialect = "built")] //! #[custom_mir(dialect = "built")]
//! fn borrow_error(should_init: bool) -> i32 { //! fn borrow_error(should_init: bool) -> i32 {
//! mir!( //! mir! {
//! let temp: i32; //! let temp: i32;
//! //!
//! { //! {
@ -171,7 +173,7 @@
//! RET = temp; //! RET = temp;
//! Return() //! Return()
//! } //! }
//! ) //! }
//! } //! }
//! ``` //! ```
//! //!
@ -179,7 +181,7 @@
//! error[E0381]: used binding is possibly-uninitialized //! error[E0381]: used binding is possibly-uninitialized
//! --> test.rs:24:13 //! --> test.rs:24:13
//! | //! |
//! 8 | / mir!( //! 8 | / mir! {
//! 9 | | let temp: i32; //! 9 | | let temp: i32;
//! 10 | | //! 10 | |
//! 11 | | { //! 11 | | {
@ -191,7 +193,7 @@
//! | | ^^^^^^^^^^ value used here but it is possibly-uninitialized //! | | ^^^^^^^^^^ value used here but it is possibly-uninitialized
//! 25 | | Return() //! 25 | | Return()
//! 26 | | } //! 26 | | }
//! 27 | | ) //! 27 | | }
//! | |_____- binding declared here but left uninitialized //! | |_____- binding declared here but left uninitialized
//! //!
//! error: aborting due to 1 previous error //! error: aborting due to 1 previous error
@ -407,18 +409,22 @@ define!(
/// ///
/// #[custom_mir(dialect = "built")] /// #[custom_mir(dialect = "built")]
/// fn unwrap_deref(opt: Option<&i32>) -> i32 { /// fn unwrap_deref(opt: Option<&i32>) -> i32 {
/// mir!({ /// mir! {
/// RET = *Field::<&i32>(Variant(opt, 1), 0); /// {
/// Return() /// RET = *Field::<&i32>(Variant(opt, 1), 0);
/// }) /// Return()
/// }
/// }
/// } /// }
/// ///
/// #[custom_mir(dialect = "built")] /// #[custom_mir(dialect = "built")]
/// fn set(opt: &mut Option<i32>) { /// fn set(opt: &mut Option<i32>) {
/// mir!({ /// mir! {
/// place!(Field(Variant(*opt, 1), 0)) = 5; /// {
/// Return() /// place!(Field(Variant(*opt, 1), 0)) = 5;
/// }) /// Return()
/// }
/// }
/// } /// }
/// ``` /// ```
fn Field<F>(place: (), field: u32) -> F fn Field<F>(place: (), field: u32) -> F
@ -455,7 +461,7 @@ define!(
/// your MIR into something that is easier to parse in the compiler. /// your MIR into something that is easier to parse in the compiler.
#[rustc_macro_transparency = "transparent"] #[rustc_macro_transparency = "transparent"]
pub macro mir { pub macro mir {
( {
$(type RET = $ret_ty:ty ;)? $(type RET = $ret_ty:ty ;)?
$(let $local_decl:ident $(: $local_decl_ty:ty)? ;)* $(let $local_decl:ident $(: $local_decl_ty:ty)? ;)*
$(debug $dbg_name:ident => $dbg_data:expr ;)* $(debug $dbg_name:ident => $dbg_data:expr ;)*
@ -469,7 +475,7 @@ pub macro mir {
$($block:tt)* $($block:tt)*
} }
)* )*
) => {{ } => {{
// First, we declare all basic blocks. // First, we declare all basic blocks.
__internal_declare_basic_blocks!($( __internal_declare_basic_blocks!($(
$block_name $(($block_cleanup))? $block_name $(($block_cleanup))?

View File

@ -7,10 +7,12 @@ use std::intrinsics::mir::*;
#[custom_mir(dialect = "runtime")] #[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize { pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
mir!({ mir! {
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data {
Return() RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_slice_data.rs:LL:CC --> $DIR/ptr_metadata_uninit_slice_data.rs:LL:CC
| |
LL | RET = PtrMetadata(*p); LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory | ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
| |
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

View File

@ -7,10 +7,12 @@ use std::intrinsics::mir::*;
#[custom_mir(dialect = "runtime")] #[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize { pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
mir!({ mir! {
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data {
Return() RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -16,8 +16,8 @@ LL | (*p.as_mut_ptr().cast::<[*const i32; 2]>())[0] = 4 as *const i32;
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_slice_len.rs:LL:CC --> $DIR/ptr_metadata_uninit_slice_len.rs:LL:CC
| |
LL | RET = PtrMetadata(*p); LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory | ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
| |
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

View File

@ -7,10 +7,12 @@ use std::intrinsics::mir::*;
#[custom_mir(dialect = "runtime")] #[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const i32) -> () { pub unsafe fn deref_meta(p: *const *const i32) -> () {
mir!({ mir! {
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data {
Return() RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_thin.rs:LL:CC --> $DIR/ptr_metadata_uninit_thin.rs:LL:CC
| |
LL | RET = PtrMetadata(*p); LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory | ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
| |
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

View File

@ -7,18 +7,18 @@ use core::intrinsics::mir::*;
// EMIT_MIR aggregate_exprs.tuple.built.after.mir // EMIT_MIR aggregate_exprs.tuple.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn tuple() -> (i32, bool) { fn tuple() -> (i32, bool) {
mir!( mir! {
{ {
RET = (1, true); RET = (1, true);
Return() Return()
} }
) }
} }
// EMIT_MIR aggregate_exprs.array.built.after.mir // EMIT_MIR aggregate_exprs.array.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn array() -> [i32; 2] { fn array() -> [i32; 2] {
mir!( mir! {
let x: [i32; 2]; let x: [i32; 2];
let one: i32; let one: i32;
{ {
@ -28,7 +28,7 @@ fn array() -> [i32; 2] {
RET = Move(x); RET = Move(x);
Return() Return()
} }
) }
} }
struct Foo { struct Foo {
@ -48,7 +48,7 @@ union Onion {
// EMIT_MIR aggregate_exprs.adt.built.after.mir // EMIT_MIR aggregate_exprs.adt.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn adt() -> Onion { fn adt() -> Onion {
mir!( mir! {
let one: i32; let one: i32;
let x: Foo; let x: Foo;
let y: Bar; let y: Bar;
@ -62,7 +62,7 @@ fn adt() -> Onion {
RET = Onion { neon: Field(Variant(y, 0), 1) }; RET = Onion { neon: Field(Variant(y, 0), 1) };
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -8,7 +8,7 @@ use core::ptr::{addr_of, addr_of_mut};
// EMIT_MIR arbitrary_let.arbitrary_let.built.after.mir // EMIT_MIR arbitrary_let.arbitrary_let.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn arbitrary_let(x: i32) -> i32 { fn arbitrary_let(x: i32) -> i32 {
mir!( mir! {
{ {
let y = x; let y = x;
Goto(second) Goto(second)
@ -21,7 +21,7 @@ fn arbitrary_let(x: i32) -> i32 {
let z = y; let z = y;
Goto(third) Goto(third)
} }
) }
} }
fn main() { fn main() {

View File

@ -7,12 +7,14 @@ use core::intrinsics::mir::*;
// EMIT_MIR arrays.arrays.built.after.mir // EMIT_MIR arrays.arrays.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn arrays<const C: usize>() -> usize { fn arrays<const C: usize>() -> usize {
mir!({ mir! {
let x = [5_i32; C]; {
let c = Len(x); let x = [5_i32; C];
RET = c; let c = Len(x);
Return() RET = c;
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -7,34 +7,34 @@ use core::intrinsics::mir::*;
// EMIT_MIR as_cast.int_to_int.built.after.mir // EMIT_MIR as_cast.int_to_int.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn int_to_int(x: u32) -> i32 { fn int_to_int(x: u32) -> i32 {
mir!( mir! {
{ {
RET = x as i32; RET = x as i32;
Return() Return()
} }
) }
} }
// EMIT_MIR as_cast.float_to_int.built.after.mir // EMIT_MIR as_cast.float_to_int.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn float_to_int(x: f32) -> i32 { fn float_to_int(x: f32) -> i32 {
mir!( mir! {
{ {
RET = x as i32; RET = x as i32;
Return() Return()
} }
) }
} }
// EMIT_MIR as_cast.int_to_ptr.built.after.mir // EMIT_MIR as_cast.int_to_ptr.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn int_to_ptr(x: usize) -> *const i32 { fn int_to_ptr(x: usize) -> *const i32 {
mir!( mir! {
{ {
RET = x as *const i32; RET = x as *const i32;
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -7,34 +7,34 @@ use core::intrinsics::mir::*;
// EMIT_MIR assume.assume_local.built.after.mir // EMIT_MIR assume.assume_local.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn assume_local(x: bool) { fn assume_local(x: bool) {
mir!( mir! {
{ {
Assume(x); Assume(x);
Return() Return()
} }
) }
} }
// EMIT_MIR assume.assume_place.built.after.mir // EMIT_MIR assume.assume_place.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn assume_place(p: (bool, u8)) { fn assume_place(p: (bool, u8)) {
mir!( mir! {
{ {
Assume(p.0); Assume(p.0);
Return() Return()
} }
) }
} }
// EMIT_MIR assume.assume_constant.built.after.mir // EMIT_MIR assume.assume_constant.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn assume_constant() { fn assume_constant() {
mir!( mir! {
{ {
Assume(true); Assume(true);
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -7,14 +7,14 @@ use core::intrinsics::mir::*;
// EMIT_MIR composite_return.tuple.built.after.mir // EMIT_MIR composite_return.tuple.built.after.mir
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
fn tuple() -> (i32, bool) { fn tuple() -> (i32, bool) {
mir!( mir! {
type RET = (i32, bool); type RET = (i32, bool);
{ {
RET.0 = 1; RET.0 = 1;
RET.1 = true; RET.1 = true;
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -9,14 +9,16 @@ const D: i32 = 5;
// EMIT_MIR consts.consts.built.after.mir // EMIT_MIR consts.consts.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn consts<const C: u32>() { fn consts<const C: u32>() {
mir!({ mir! {
let _a = 5_u8; {
let _b = const { 5_i8 }; let _a = 5_u8;
let _c = C; let _b = const { 5_i8 };
let _d = D; let _c = C;
let _e = consts::<10>; let _d = D;
Return() let _e = consts::<10>;
}) Return()
}
}
} }
static S: i32 = 0x05050505; static S: i32 = 0x05050505;
@ -24,11 +26,13 @@ static mut T: i32 = 0x0a0a0a0a;
// EMIT_MIR consts.statics.built.after.mir // EMIT_MIR consts.statics.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn statics() { fn statics() {
mir!({ mir! {
let _a: &i32 = Static(S); {
let _b: *mut i32 = StaticMut(T); let _a: &i32 = Static(S);
Return() let _b: *mut i32 = StaticMut(T);
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -7,24 +7,24 @@ use core::intrinsics::mir::*;
// EMIT_MIR debuginfo.pointee.built.after.mir // EMIT_MIR debuginfo.pointee.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn pointee(opt: &mut Option<i32>) { fn pointee(opt: &mut Option<i32>) {
mir!( mir! {
debug foo => Field::<i32>(Variant(*opt, 1), 0); debug foo => Field::<i32>(Variant(*opt, 1), 0);
{ {
Return() Return()
} }
) }
} }
// EMIT_MIR debuginfo.numbered.built.after.mir // EMIT_MIR debuginfo.numbered.built.after.mir
#[custom_mir(dialect = "analysis", phase = "post-cleanup")] #[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn numbered(i: (u32, i32)) { fn numbered(i: (u32, i32)) {
mir!( mir! {
debug first => i.0; debug first => i.0;
debug second => i.0; debug second => i.0;
{ {
Return() Return()
} }
) }
} }
struct S { x: f32 } struct S { x: f32 }
@ -32,35 +32,35 @@ struct S { x: f32 }
// EMIT_MIR debuginfo.structured.built.after.mir // EMIT_MIR debuginfo.structured.built.after.mir
#[custom_mir(dialect = "analysis", phase = "post-cleanup")] #[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn structured(i: S) { fn structured(i: S) {
mir!( mir! {
debug x => i.x; debug x => i.x;
{ {
Return() Return()
} }
) }
} }
// EMIT_MIR debuginfo.variant.built.after.mir // EMIT_MIR debuginfo.variant.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn variant(opt: Option<i32>) { fn variant(opt: Option<i32>) {
mir!( mir! {
debug inner => Field::<i32>(Variant(opt, 1), 0); debug inner => Field::<i32>(Variant(opt, 1), 0);
{ {
Return() Return()
} }
) }
} }
// EMIT_MIR debuginfo.variant_deref.built.after.mir // EMIT_MIR debuginfo.variant_deref.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn variant_deref(opt: Option<&i32>) { fn variant_deref(opt: Option<&i32>) {
mir!( mir! {
debug pointer => Field::<&i32>(Variant(opt, 1), 0); debug pointer => Field::<&i32>(Variant(opt, 1), 0);
debug deref => *Field::<&i32>(Variant(opt, 1), 0); debug deref => *Field::<&i32>(Variant(opt, 1), 0);
{ {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -7,7 +7,7 @@ use core::intrinsics::mir::*;
// EMIT_MIR enums.switch_bool.built.after.mir // EMIT_MIR enums.switch_bool.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn switch_bool(b: bool) -> u32 { pub fn switch_bool(b: bool) -> u32 {
mir!( mir! {
{ {
match b { match b {
true => t, true => t,
@ -25,13 +25,13 @@ pub fn switch_bool(b: bool) -> u32 {
RET = 10; RET = 10;
Return() Return()
} }
) }
} }
// EMIT_MIR enums.switch_option.built.after.mir // EMIT_MIR enums.switch_option.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn switch_option(option: Option<()>) -> bool { pub fn switch_option(option: Option<()>) -> bool {
mir!( mir! {
{ {
let discr = Discriminant(option); let discr = Discriminant(option);
match discr { match discr {
@ -50,7 +50,7 @@ pub fn switch_option(option: Option<()>) -> bool {
RET = true; RET = true;
Return() Return()
} }
) }
} }
#[repr(u8)] #[repr(u8)]
@ -62,7 +62,7 @@ enum Bool {
// EMIT_MIR enums.switch_option_repr.built.after.mir // EMIT_MIR enums.switch_option_repr.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn switch_option_repr(option: Bool) -> bool { fn switch_option_repr(option: Bool) -> bool {
mir!( mir! {
{ {
let discr = Discriminant(option); let discr = Discriminant(option);
match discr { match discr {
@ -80,26 +80,30 @@ fn switch_option_repr(option: Bool) -> bool {
RET = false; RET = false;
Return() Return()
} }
) }
} }
// EMIT_MIR enums.set_discr.built.after.mir // EMIT_MIR enums.set_discr.built.after.mir
#[custom_mir(dialect = "runtime", phase = "initial")] #[custom_mir(dialect = "runtime", phase = "initial")]
fn set_discr(option: &mut Option<()>) { fn set_discr(option: &mut Option<()>) {
mir!({ mir! {
Deinit(*option); {
SetDiscriminant(*option, 0); Deinit(*option);
Return() SetDiscriminant(*option, 0);
}) Return()
}
}
} }
// EMIT_MIR enums.set_discr_repr.built.after.mir // EMIT_MIR enums.set_discr_repr.built.after.mir
#[custom_mir(dialect = "runtime", phase = "initial")] #[custom_mir(dialect = "runtime", phase = "initial")]
fn set_discr_repr(b: &mut Bool) { fn set_discr_repr(b: &mut Bool) {
mir!({ mir! {
SetDiscriminant(*b, 0); {
Return() SetDiscriminant(*b, 0);
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -6,37 +6,41 @@ use std::intrinsics::mir::*;
// EMIT_MIR operators.f.built.after.mir // EMIT_MIR operators.f.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn f(a: i32, b: bool) -> i32 { pub fn f(a: i32, b: bool) -> i32 {
mir!({ mir! {
a = -a; {
b = !b; a = -a;
a = a + a; b = !b;
a = a - a; a = a + a;
a = a * a; a = a - a;
a = a / a; a = a * a;
a = a % a; a = a / a;
a = a ^ a; a = a % a;
a = a & a; a = a ^ a;
a = a << a; a = a & a;
a = a >> a; a = a << a;
b = a == a; a = a >> a;
b = a < a; b = a == a;
b = a <= a; b = a < a;
b = a >= a; b = a <= a;
b = a > a; b = a >= a;
let res = Checked(a + a); b = a > a;
b = res.1; let res = Checked(a + a);
a = res.0; b = res.1;
RET = a; a = res.0;
Return() RET = a;
}) Return()
}
}
} }
// EMIT_MIR operators.g.runtime.after.mir // EMIT_MIR operators.g.runtime.after.mir
#[custom_mir(dialect = "runtime")] #[custom_mir(dialect = "runtime")]
pub fn g(p: *const i32, q: *const [i32]) { pub fn g(p: *const i32, q: *const [i32]) {
mir!({ mir! {
let a = PtrMetadata(p); {
let b = PtrMetadata(q); let a = PtrMetadata(p);
Return() let b = PtrMetadata(q);
}) Return()
}
}
} }

View File

@ -12,74 +12,84 @@ union U {
// EMIT_MIR projections.unions.built.after.mir // EMIT_MIR projections.unions.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn unions(u: U) -> i32 { fn unions(u: U) -> i32 {
mir!({ mir! {
RET = u.a; {
Return() RET = u.a;
}) Return()
}
}
} }
// EMIT_MIR projections.tuples.built.after.mir // EMIT_MIR projections.tuples.built.after.mir
#[custom_mir(dialect = "analysis", phase = "post-cleanup")] #[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn tuples(i: (u32, i32)) -> (u32, i32) { fn tuples(i: (u32, i32)) -> (u32, i32) {
mir!( mir! {
type RET = (u32, i32); type RET = (u32, i32);
{ {
RET.0 = i.0; RET.0 = i.0;
RET.1 = i.1; RET.1 = i.1;
Return() Return()
} }
) }
} }
// EMIT_MIR projections.unwrap.built.after.mir // EMIT_MIR projections.unwrap.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn unwrap(opt: Option<i32>) -> i32 { fn unwrap(opt: Option<i32>) -> i32 {
mir!({ mir! {
RET = Field(Variant(opt, 1), 0); {
Return() RET = Field(Variant(opt, 1), 0);
}) Return()
}
}
} }
// EMIT_MIR projections.unwrap_deref.built.after.mir // EMIT_MIR projections.unwrap_deref.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn unwrap_deref(opt: Option<&i32>) -> i32 { fn unwrap_deref(opt: Option<&i32>) -> i32 {
mir!({ mir! {
RET = *Field::<&i32>(Variant(opt, 1), 0); {
Return() RET = *Field::<&i32>(Variant(opt, 1), 0);
}) Return()
}
}
} }
// EMIT_MIR projections.set.built.after.mir // EMIT_MIR projections.set.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn set(opt: &mut Option<i32>) { fn set(opt: &mut Option<i32>) {
mir!({ mir! {
place!(Field(Variant(*opt, 1), 0)) = 10; {
Return() place!(Field(Variant(*opt, 1), 0)) = 10;
}) Return()
}
}
} }
// EMIT_MIR projections.simple_index.built.after.mir // EMIT_MIR projections.simple_index.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn simple_index(a: [i32; 10], b: &[i32]) -> i32 { fn simple_index(a: [i32; 10], b: &[i32]) -> i32 {
mir!({ mir! {
let temp = 3; {
RET = a[temp]; let temp = 3;
RET = (*b)[temp]; RET = a[temp];
Return() RET = (*b)[temp];
}) Return()
}
}
} }
// EMIT_MIR projections.copy_for_deref.built.after.mir // EMIT_MIR projections.copy_for_deref.built.after.mir
#[custom_mir(dialect = "runtime", phase = "initial")] #[custom_mir(dialect = "runtime", phase = "initial")]
fn copy_for_deref(x: (&i32, i32)) -> i32 { fn copy_for_deref(x: (&i32, i32)) -> i32 {
mir!( mir! {
let temp: &i32; let temp: &i32;
{ {
temp = CopyForDeref(x.0); temp = CopyForDeref(x.0);
RET = *temp; RET = *temp;
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -8,31 +8,29 @@ use core::ptr::{addr_of, addr_of_mut};
// EMIT_MIR references.mut_ref.built.after.mir // EMIT_MIR references.mut_ref.built.after.mir
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn mut_ref(x: &mut i32) -> &mut i32 { pub fn mut_ref(x: &mut i32) -> &mut i32 {
mir!( mir! {
let t: *mut i32; let t: *mut i32;
{ {
t = addr_of_mut!(*x); t = addr_of_mut!(*x);
RET = &mut *t; RET = &mut *t;
Retag(RET); Retag(RET);
Return() Return()
} }
) }
} }
// EMIT_MIR references.immut_ref.built.after.mir // EMIT_MIR references.immut_ref.built.after.mir
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn immut_ref(x: &i32) -> &i32 { pub fn immut_ref(x: &i32) -> &i32 {
mir!( mir! {
let t: *const i32; let t: *const i32;
{ {
t = addr_of!(*x); t = addr_of!(*x);
RET = & *t; RET = & *t;
Retag(RET); Retag(RET);
Return() Return()
} }
) }
} }
// EMIT_MIR references.raw_pointer.built.after.mir // EMIT_MIR references.raw_pointer.built.after.mir
@ -40,19 +38,23 @@ pub fn immut_ref(x: &i32) -> &i32 {
pub fn raw_pointer(x: *const i32) -> *const i32 { pub fn raw_pointer(x: *const i32) -> *const i32 {
// Regression test for a bug in which unsafetyck was not correctly turned off for // Regression test for a bug in which unsafetyck was not correctly turned off for
// `dialect = "built"` // `dialect = "built"`
mir!({ mir! {
RET = addr_of!(*x); {
Return() RET = addr_of!(*x);
}) Return()
}
}
} }
// EMIT_MIR references.raw_pointer_offset.built.after.mir // EMIT_MIR references.raw_pointer_offset.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn raw_pointer_offset(x: *const i32) -> *const i32 { pub fn raw_pointer_offset(x: *const i32) -> *const i32 {
mir!({ mir! {
RET = Offset(x, 1_isize); {
Return() RET = Offset(x, 1_isize);
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -7,32 +7,32 @@ use core::intrinsics::mir::*;
// EMIT_MIR simple_assign.simple.built.after.mir // EMIT_MIR simple_assign.simple.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn simple(x: i32) -> i32 { pub fn simple(x: i32) -> i32 {
mir!( mir! {
let temp1: i32; let temp1: i32;
let temp2: _; let temp2: _;
{ {
StorageLive(temp1); StorageLive(temp1);
temp1 = x; temp1 = x;
Goto(exit) Goto(exit)
} }
exit = { exit = {
temp2 = Move(temp1); temp2 = Move(temp1);
StorageDead(temp1); StorageDead(temp1);
RET = temp2; RET = temp2;
Return() Return()
} }
) }
} }
// EMIT_MIR simple_assign.simple_ref.built.after.mir // EMIT_MIR simple_assign.simple_ref.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn simple_ref(x: &mut i32) -> &mut i32 { pub fn simple_ref(x: &mut i32) -> &mut i32 {
mir!({ mir! {
RET = Move(x); {
Return() RET = Move(x);
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -11,7 +11,7 @@ fn ident<T>(t: T) -> T {
// EMIT_MIR terminators.direct_call.built.after.mir // EMIT_MIR terminators.direct_call.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn direct_call(x: i32) -> i32 { fn direct_call(x: i32) -> i32 {
mir!( mir! {
{ {
Call(RET = ident(x), ReturnTo(retblock), UnwindContinue()) Call(RET = ident(x), ReturnTo(retblock), UnwindContinue())
} }
@ -19,21 +19,20 @@ fn direct_call(x: i32) -> i32 {
retblock = { retblock = {
Return() Return()
} }
) }
} }
// EMIT_MIR terminators.indirect_call.built.after.mir // EMIT_MIR terminators.indirect_call.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn indirect_call(x: i32, f: fn(i32) -> i32) -> i32 { fn indirect_call(x: i32, f: fn(i32) -> i32) -> i32 {
mir!( mir! {
{ {
Call(RET = f(x), ReturnTo(retblock), UnwindContinue()) Call(RET = f(x), ReturnTo(retblock), UnwindContinue())
} }
retblock = { retblock = {
Return() Return()
} }
) }
} }
struct WriteOnDrop<'a>(&'a mut i32, i32); struct WriteOnDrop<'a>(&'a mut i32, i32);
@ -47,51 +46,47 @@ impl<'a> Drop for WriteOnDrop<'a> {
// EMIT_MIR terminators.drop_first.built.after.mir // EMIT_MIR terminators.drop_first.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn drop_first<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) { fn drop_first<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) {
mir!( mir! {
{ {
Drop(a, ReturnTo(retblock), UnwindContinue()) Drop(a, ReturnTo(retblock), UnwindContinue())
} }
retblock = { retblock = {
a = Move(b); a = Move(b);
Return() Return()
} }
) }
} }
// EMIT_MIR terminators.drop_second.built.after.mir // EMIT_MIR terminators.drop_second.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn drop_second<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) { fn drop_second<'a>(a: WriteOnDrop<'a>, b: WriteOnDrop<'a>) {
mir!( mir! {
{ {
Drop(b, ReturnTo(retblock), UnwindContinue()) Drop(b, ReturnTo(retblock), UnwindContinue())
} }
retblock = { retblock = {
Return() Return()
} }
) }
} }
// EMIT_MIR terminators.assert_nonzero.built.after.mir // EMIT_MIR terminators.assert_nonzero.built.after.mir
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn assert_nonzero(a: i32) { fn assert_nonzero(a: i32) {
mir!( mir! {
{ {
match a { match a {
0 => unreachable, 0 => unreachable,
_ => retblock _ => retblock
} }
} }
unreachable = { unreachable = {
Unreachable() Unreachable()
} }
retblock = { retblock = {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -9,14 +9,14 @@ use core::intrinsics::mir::*;
// CHECK-NEXT: a() -> [return: bb1, unwind unreachable]; // CHECK-NEXT: a() -> [return: bb1, unwind unreachable];
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn a() { pub fn a() {
mir!( mir! {
{ {
Call(RET = a(), ReturnTo(bb1), UnwindUnreachable()) Call(RET = a(), ReturnTo(bb1), UnwindUnreachable())
} }
bb1 = { bb1 = {
Return() Return()
} }
) }
} }
// CHECK-LABEL: fn b() // CHECK-LABEL: fn b()
@ -24,14 +24,14 @@ pub fn a() {
// CHECK-NEXT: b() -> [return: bb1, unwind continue]; // CHECK-NEXT: b() -> [return: bb1, unwind continue];
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn b() { pub fn b() {
mir!( mir! {
{ {
Call(RET = b(), ReturnTo(bb1), UnwindContinue()) Call(RET = b(), ReturnTo(bb1), UnwindContinue())
} }
bb1 = { bb1 = {
Return() Return()
} }
) }
} }
// CHECK-LABEL: fn c() // CHECK-LABEL: fn c()
@ -39,14 +39,14 @@ pub fn b() {
// CHECK-NEXT: c() -> [return: bb1, unwind terminate(abi)]; // CHECK-NEXT: c() -> [return: bb1, unwind terminate(abi)];
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn c() { pub fn c() {
mir!( mir! {
{ {
Call(RET = c(), ReturnTo(bb1), UnwindTerminate(ReasonAbi)) Call(RET = c(), ReturnTo(bb1), UnwindTerminate(ReasonAbi))
} }
bb1 = { bb1 = {
Return() Return()
} }
) }
} }
// CHECK-LABEL: fn d() // CHECK-LABEL: fn d()
@ -54,7 +54,7 @@ pub fn c() {
// CHECK-NEXT: d() -> [return: bb1, unwind: bb2]; // CHECK-NEXT: d() -> [return: bb1, unwind: bb2];
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn d() { pub fn d() {
mir!( mir! {
{ {
Call(RET = d(), ReturnTo(bb1), UnwindCleanup(bb2)) Call(RET = d(), ReturnTo(bb1), UnwindCleanup(bb2))
} }
@ -64,5 +64,5 @@ pub fn d() {
bb2 (cleanup) = { bb2 (cleanup) = {
UnwindResume() UnwindResume()
} }
) }
} }

View File

@ -8,14 +8,14 @@ use core::intrinsics::mir::*;
// CHECK-NEXT: terminate(abi); // CHECK-NEXT: terminate(abi);
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn f() { pub fn f() {
mir!( mir! {
{ {
Return() Return()
} }
bb1(cleanup) = { bb1(cleanup) = {
UnwindTerminate(ReasonAbi) UnwindTerminate(ReasonAbi)
} }
) }
} }
// CHECK-LABEL: fn g() // CHECK-LABEL: fn g()
@ -23,12 +23,12 @@ pub fn f() {
// CHECK-NEXT: terminate(cleanup); // CHECK-NEXT: terminate(cleanup);
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn g() { pub fn g() {
mir!( mir! {
{ {
Return() Return()
} }
bb1(cleanup) = { bb1(cleanup) = {
UnwindTerminate(ReasonInCleanup) UnwindTerminate(ReasonInCleanup)
} }
) }
} }

View File

@ -24,7 +24,7 @@ fn compare_address() -> bool {
// CHECK-NEXT: _0 = cmp_ref(_2, _4) // CHECK-NEXT: _0 = cmp_ref(_2, _4)
// CHECK: bb1: { // CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<u8>(_3) // CHECK-NEXT: _0 = opaque::<u8>(_3)
mir!( mir! {
{ {
let a = 5_u8; let a = 5_u8;
let r1 = &a; let r1 = &a;
@ -40,7 +40,7 @@ fn compare_address() -> bool {
ret = { ret = {
Return() Return()
} }
) }
} }
/// Generic type `T` is `Freeze`, so shared borrows are immutable. /// Generic type `T` is `Freeze`, so shared borrows are immutable.
@ -52,7 +52,7 @@ fn borrowed<T: Copy + Freeze>(x: T) -> bool {
// CHECK-NEXT: _0 = opaque::<&T>(_3) // CHECK-NEXT: _0 = opaque::<&T>(_3)
// CHECK: bb1: { // CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<T>(_1) // CHECK-NEXT: _0 = opaque::<T>(_1)
mir!( mir! {
{ {
let a = x; let a = x;
let r1 = &x; let r1 = &x;
@ -64,7 +64,7 @@ fn borrowed<T: Copy + Freeze>(x: T) -> bool {
ret = { ret = {
Return() Return()
} }
) }
} }
/// Generic type `T` is not known to be `Freeze`, so shared borrows may be mutable. /// Generic type `T` is not known to be `Freeze`, so shared borrows may be mutable.
@ -77,7 +77,7 @@ fn non_freeze<T: Copy>(x: T) -> bool {
// CHECK-NEXT: _0 = opaque::<&T>(_3) // CHECK-NEXT: _0 = opaque::<&T>(_3)
// CHECK: bb1: { // CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<T>(_2) // CHECK-NEXT: _0 = opaque::<T>(_2)
mir!( mir! {
{ {
let a = x; let a = x;
let r1 = &x; let r1 = &x;
@ -89,7 +89,7 @@ fn non_freeze<T: Copy>(x: T) -> bool {
ret = { ret = {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -12,17 +12,19 @@ struct NotCopy(bool);
// EMIT_MIR custom_move_arg.f.CopyProp.diff // EMIT_MIR custom_move_arg.f.CopyProp.diff
#[custom_mir(dialect = "runtime")] #[custom_mir(dialect = "runtime")]
fn f(_1: NotCopy) { fn f(_1: NotCopy) {
mir!({ mir! {
let _2 = _1; {
Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable()) let _2 = _1;
Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable())
}
bb1 = {
let _3 = Move(_2);
Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable())
}
bb2 = {
Return()
}
} }
bb1 = {
let _3 = Move(_2);
Call(RET = opaque(_3), ReturnTo(bb2), UnwindUnreachable())
}
bb2 = {
Return()
})
} }
#[inline(never)] #[inline(never)]

View File

@ -13,7 +13,7 @@ struct Foo(u8);
#[custom_mir(dialect = "runtime")] #[custom_mir(dialect = "runtime")]
fn f(a: Foo) -> bool { fn f(a: Foo) -> bool {
mir!( mir! {
{ {
let b = a; let b = a;
// This is a move out of a copy, so must become a copy of `a.0`. // This is a move out of a copy, so must become a copy of `a.0`.
@ -26,7 +26,7 @@ fn f(a: Foo) -> bool {
ret = { ret = {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -18,14 +18,16 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "analysis", phase = "post-cleanup")] #[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn f(c: bool) -> bool { fn f(c: bool) -> bool {
mir!({ mir! {
let a = c; {
let p = core::ptr::addr_of!(a); let a = c;
let p2 = core::ptr::addr_of_mut!(*p); let p = core::ptr::addr_of!(a);
*p2 = false; let p2 = core::ptr::addr_of_mut!(*p);
RET = c; *p2 = false;
Return() RET = c;
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -8,16 +8,28 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "analysis", phase = "post-cleanup")] #[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn f(c: bool) -> bool { fn f(c: bool) -> bool {
mir!( mir! {
let a: bool; let a: bool;
let b: bool; let b: bool;
{ Goto(bb1) } {
bb1 = { b = c; match b { false => bb3, _ => bb2 }} Goto(bb1)
}
bb1 = {
b = c;
match b { false => bb3, _ => bb2 }
}
// This assignment to `a` does not dominate the use in `bb3`. // This assignment to `a` does not dominate the use in `bb3`.
// It should not be replaced by `b`. // It should not be replaced by `b`.
bb2 = { a = b; c = false; Goto(bb1) } bb2 = {
bb3 = { RET = a; Return() } a = b;
) c = false;
Goto(bb1)
}
bb3 = {
RET = a;
Return()
}
}
} }
fn main() { fn main() {

View File

@ -84,7 +84,7 @@ struct NonZeroUsize(usize);
// CHECK-LABEL: fn mutate_discriminant( // CHECK-LABEL: fn mutate_discriminant(
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn mutate_discriminant() -> u8 { fn mutate_discriminant() -> u8 {
mir!( mir! {
let x: Option<NonZeroUsize>; let x: Option<NonZeroUsize>;
{ {
SetDiscriminant(x, 1); SetDiscriminant(x, 1);
@ -109,7 +109,7 @@ fn mutate_discriminant() -> u8 {
RET = 2; RET = 2;
Unreachable() Unreachable()
} }
) }
} }
// EMIT_MIR enum.multiple.DataflowConstProp.diff // EMIT_MIR enum.multiple.DataflowConstProp.diff

View File

@ -29,7 +29,7 @@ struct Packed {
fn move_packed(packed: Packed) { fn move_packed(packed: Packed) {
// CHECK-LABEL: fn move_packed( // CHECK-LABEL: fn move_packed(
// CHECK: = use_both(const 0_i32, (_1.1: i32)) // CHECK: = use_both(const 0_i32, (_1.1: i32))
mir!( mir! {
{ {
// We have a packed struct, verify that the copy is not turned into a move. // We have a packed struct, verify that the copy is not turned into a move.
Call(RET = use_both(0, packed.y), ReturnTo(ret), UnwindContinue()) Call(RET = use_both(0, packed.y), ReturnTo(ret), UnwindContinue())
@ -37,7 +37,7 @@ fn move_packed(packed: Packed) {
ret = { ret = {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -20,7 +20,7 @@ fn cycle(mut x: i32, mut y: i32, mut z: i32) {
// CHECK-NOT: {{_.*}} = move {{_.*}}; // CHECK-NOT: {{_.*}} = move {{_.*}};
// We use custom MIR to avoid generating debuginfo, that would force to preserve writes. // We use custom MIR to avoid generating debuginfo, that would force to preserve writes.
mir!( mir! {
let condition: bool; let condition: bool;
{ {
Call(condition = cond(), ReturnTo(bb1), UnwindContinue()) Call(condition = cond(), ReturnTo(bb1), UnwindContinue())
@ -38,7 +38,7 @@ fn cycle(mut x: i32, mut y: i32, mut z: i32) {
ret = { ret = {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -539,7 +539,7 @@ fn slices() {
#[custom_mir(dialect = "analysis")] #[custom_mir(dialect = "analysis")]
fn duplicate_slice() -> (bool, bool) { fn duplicate_slice() -> (bool, bool) {
// CHECK-LABEL: fn duplicate_slice( // CHECK-LABEL: fn duplicate_slice(
mir!( mir! {
let au: u128; let au: u128;
let bu: u128; let bu: u128;
let cu: u128; let cu: u128;
@ -585,7 +585,7 @@ fn duplicate_slice() -> (bool, bool) {
RET = (direct, indirect); RET = (direct, indirect);
Return() Return()
} }
) }
} }
fn repeat() { fn repeat() {
@ -623,11 +623,13 @@ fn fn_pointers() {
fn indirect_static() { fn indirect_static() {
static A: Option<u8> = None; static A: Option<u8> = None;
mir!({ mir! {
let ptr = Static(A); {
let out = Field::<u8>(Variant(*ptr, 1), 0); let ptr = Static(A);
Return() let out = Field::<u8>(Variant(*ptr, 1), 0);
}) Return()
}
}
} }
/// Verify that having constant index `u64::MAX` does not yield to an overflow in rustc. /// Verify that having constant index `u64::MAX` does not yield to an overflow in rustc.
@ -733,7 +735,7 @@ fn borrowed<T: Copy + Freeze>(x: T) {
// CHECK-NEXT: _0 = opaque::<T>(_1) // CHECK-NEXT: _0 = opaque::<T>(_1)
// CHECK: bb2: { // CHECK: bb2: {
// CHECK-NEXT: _0 = opaque::<T>(_1) // CHECK-NEXT: _0 = opaque::<T>(_1)
mir!( mir! {
{ {
let a = x; let a = x;
let r1 = &x; let r1 = &x;
@ -748,7 +750,7 @@ fn borrowed<T: Copy + Freeze>(x: T) {
ret = { ret = {
Return() Return()
} }
) }
} }
/// Generic type `T` is not known to be `Freeze`, so shared borrows may be mutable. /// Generic type `T` is not known to be `Freeze`, so shared borrows may be mutable.
@ -763,7 +765,7 @@ fn non_freeze<T: Copy>(x: T) {
// CHECK-NEXT: _0 = opaque::<T>(_2) // CHECK-NEXT: _0 = opaque::<T>(_2)
// CHECK: bb2: { // CHECK: bb2: {
// CHECK-NEXT: _0 = opaque::<T>((*_3)) // CHECK-NEXT: _0 = opaque::<T>((*_3))
mir!( mir! {
{ {
let a = x; let a = x;
let r1 = &x; let r1 = &x;
@ -778,7 +780,7 @@ fn non_freeze<T: Copy>(x: T) {
ret = { ret = {
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -10,7 +10,7 @@ use std::intrinsics::mir::*;
pub unsafe fn assert_zero(x: u8) -> u8 { pub unsafe fn assert_zero(x: u8) -> u8 {
// CHECK-LABEL: fn assert_zero( // CHECK-LABEL: fn assert_zero(
// CHECK: switchInt({{.*}}) -> [0: {{bb.*}}, otherwise: {{bb.*}}] // CHECK: switchInt({{.*}}) -> [0: {{bb.*}}, otherwise: {{bb.*}}]
mir!( mir! {
{ {
match x { match x {
0 => retblock, 0 => retblock,
@ -25,5 +25,5 @@ pub unsafe fn assert_zero(x: u8) -> u8 {
RET = x; RET = x;
Return() Return()
} }
) }
} }

View File

@ -157,7 +157,7 @@ fn custom_discr(x: bool) -> u8 {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn multiple_match(x: u8) -> u8 { fn multiple_match(x: u8) -> u8 {
// CHECK-LABEL: fn multiple_match( // CHECK-LABEL: fn multiple_match(
mir!( mir! {
{ {
// CHECK: bb0: { // CHECK: bb0: {
// CHECK: switchInt([[x:_.*]]) -> [3: bb1, otherwise: bb2]; // CHECK: switchInt([[x:_.*]]) -> [3: bb1, otherwise: bb2];
@ -220,7 +220,7 @@ fn multiple_match(x: u8) -> u8 {
RET = 11; RET = 11;
Return() Return()
} }
) }
} }
/// Both 1-3-4 and 2-3-4 are threadable. As 1 and 2 are the only predecessors of 3, /// Both 1-3-4 and 2-3-4 are threadable. As 1 and 2 are the only predecessors of 3,
@ -228,7 +228,7 @@ fn multiple_match(x: u8) -> u8 {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn duplicate_chain(x: bool) -> u8 { fn duplicate_chain(x: bool) -> u8 {
// CHECK-LABEL: fn duplicate_chain( // CHECK-LABEL: fn duplicate_chain(
mir!( mir! {
let a: u8; let a: u8;
{ {
// CHECK: bb0: { // CHECK: bb0: {
@ -278,7 +278,7 @@ fn duplicate_chain(x: bool) -> u8 {
RET = 9; RET = 9;
Return() Return()
} }
) }
} }
#[rustc_layout_scalar_valid_range_start(1)] #[rustc_layout_scalar_valid_range_start(1)]
@ -292,7 +292,7 @@ fn mutate_discriminant() -> u8 {
// CHECK-NOT: goto -> {{bb.*}}; // CHECK-NOT: goto -> {{bb.*}};
// CHECK: switchInt( // CHECK: switchInt(
// CHECK-NOT: goto -> {{bb.*}}; // CHECK-NOT: goto -> {{bb.*}};
mir!( mir! {
let x: Option<NonZeroUsize>; let x: Option<NonZeroUsize>;
{ {
SetDiscriminant(x, 1); SetDiscriminant(x, 1);
@ -313,7 +313,7 @@ fn mutate_discriminant() -> u8 {
RET = 2; RET = 2;
Unreachable() Unreachable()
} }
) }
} }
/// Verify that we do not try to reason when there are mutable pointers involved. /// Verify that we do not try to reason when there are mutable pointers involved.
@ -342,7 +342,7 @@ fn mutable_ref() -> bool {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn renumbered_bb(x: bool) -> u8 { fn renumbered_bb(x: bool) -> u8 {
// CHECK-LABEL: fn renumbered_bb( // CHECK-LABEL: fn renumbered_bb(
mir!( mir! {
let a: bool; let a: bool;
let b: bool; let b: bool;
{ {
@ -398,7 +398,7 @@ fn renumbered_bb(x: bool) -> u8 {
// Duplicate of bb4. // Duplicate of bb4.
// CHECK: bb9: { // CHECK: bb9: {
// CHECK-NEXT: goto -> bb6; // CHECK-NEXT: goto -> bb6;
) }
} }
/// This function has 3 TOs: 1-4-5, 0-1-4-7-5-8 and 3-4-7-5-6 /// This function has 3 TOs: 1-4-5, 0-1-4-7-5-8 and 3-4-7-5-6
@ -408,7 +408,7 @@ fn renumbered_bb(x: bool) -> u8 {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn disappearing_bb(x: u8) -> u8 { fn disappearing_bb(x: u8) -> u8 {
// CHECK-LABEL: fn disappearing_bb( // CHECK-LABEL: fn disappearing_bb(
mir!( mir! {
let a: bool; let a: bool;
let b: bool; let b: bool;
{ {
@ -450,7 +450,7 @@ fn disappearing_bb(x: u8) -> u8 {
// CHECK: goto -> bb5; // CHECK: goto -> bb5;
// CHECK: bb10: { // CHECK: bb10: {
// CHECK: goto -> bb6; // CHECK: goto -> bb6;
) }
} }
/// Verify that we can thread jumps when we assign from an aggregate constant. /// Verify that we can thread jumps when we assign from an aggregate constant.
@ -472,7 +472,7 @@ fn aggregate(x: u8) -> u8 {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn assume(a: u8, b: bool) -> u8 { fn assume(a: u8, b: bool) -> u8 {
// CHECK-LABEL: fn assume( // CHECK-LABEL: fn assume(
mir!( mir! {
{ {
// CHECK: bb0: { // CHECK: bb0: {
// CHECK-NEXT: switchInt(_1) -> [7: bb1, otherwise: bb2] // CHECK-NEXT: switchInt(_1) -> [7: bb1, otherwise: bb2]
@ -511,7 +511,7 @@ fn assume(a: u8, b: bool) -> u8 {
} }
// CHECK: bb6: { // CHECK: bb6: {
// CHECK-NEXT: goto -> bb5; // CHECK-NEXT: goto -> bb5;
) }
} }
fn main() { fn main() {

View File

@ -88,7 +88,7 @@ fn match_u8_i16(i: EnumAu8) -> i16 {
fn match_u8_i16_2(i: EnumAu8) -> i16 { fn match_u8_i16_2(i: EnumAu8) -> i16 {
// CHECK-LABEL: fn match_u8_i16_2( // CHECK-LABEL: fn match_u8_i16_2(
// CHECK: switchInt // CHECK: switchInt
mir!( mir! {
{ {
let a = Discriminant(i); let a = Discriminant(i);
match a { match a {
@ -110,7 +110,7 @@ fn match_u8_i16_2(i: EnumAu8) -> i16 {
ret = { ret = {
Return() Return()
} }
) }
} }
// EMIT_MIR matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff // EMIT_MIR matches_reduce_branches.match_u8_i16_failed.MatchBranchSimplification.diff
@ -158,7 +158,7 @@ fn match_u8_u16(i: EnumBu8) -> u16 {
fn match_u8_u16_2(i: EnumBu8) -> i16 { fn match_u8_u16_2(i: EnumBu8) -> i16 {
// CHECK-LABEL: fn match_u8_u16_2( // CHECK-LABEL: fn match_u8_u16_2(
// CHECK: switchInt // CHECK: switchInt
mir!( mir! {
{ {
let a = Discriminant(i); let a = Discriminant(i);
match a { match a {
@ -187,7 +187,7 @@ fn match_u8_u16_2(i: EnumBu8) -> i16 {
ret = { ret = {
Return() Return()
} }
) }
} }
#[repr(i8)] #[repr(i8)]

View File

@ -10,12 +10,14 @@ use core::intrinsics::mir::*;
// EMIT_MIR nrvo_miscompile_111005.wrong.RenameReturnPlace.diff // EMIT_MIR nrvo_miscompile_111005.wrong.RenameReturnPlace.diff
#[custom_mir(dialect = "runtime", phase = "initial")] #[custom_mir(dialect = "runtime", phase = "initial")]
pub fn wrong(arg: char) -> char { pub fn wrong(arg: char) -> char {
mir!({ mir! {
let temp = arg; {
RET = temp; let temp = arg;
temp = 'b'; RET = temp;
Return() temp = 'b';
}) Return()
}
}
} }
fn main() { fn main() {

View File

@ -658,7 +658,7 @@ fn read_through_raw(x: &mut usize) -> usize {
// CHECK-NEXT: return; // CHECK-NEXT: return;
use std::intrinsics::mir::*; use std::intrinsics::mir::*;
mir!( mir! {
let r1: &mut usize; let r1: &mut usize;
let r2: &mut usize; let r2: &mut usize;
let p1: *mut usize; let p1: *mut usize;
@ -674,7 +674,7 @@ fn read_through_raw(x: &mut usize) -> usize {
RET = *p2; RET = *p2;
Return() Return()
} }
) }
} }
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@ -683,7 +683,7 @@ fn multiple_storage() {
// CHECK: _3 = (*_2); // CHECK: _3 = (*_2);
use std::intrinsics::mir::*; use std::intrinsics::mir::*;
mir!( mir! {
let x: i32; let x: i32;
{ {
StorageLive(x); StorageLive(x);
@ -700,7 +700,7 @@ fn multiple_storage() {
retblock = { retblock = {
Return() Return()
} }
) }
} }
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@ -709,7 +709,7 @@ fn dominate_storage() {
// CHECK: _5 = (*_2); // CHECK: _5 = (*_2);
use std::intrinsics::mir::*; use std::intrinsics::mir::*;
mir!( mir! {
let x: i32; let x: i32;
let r: &i32; let r: &i32;
let c: i32; let c: i32;
@ -730,7 +730,7 @@ fn dominate_storage() {
let d = true; let d = true;
match d { false => bb2, _ => bb0 } match d { false => bb2, _ => bb0 }
} }
) }
} }
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@ -739,7 +739,7 @@ fn maybe_dead(m: bool) {
// CHECK: (*_5) = const 7_i32; // CHECK: (*_5) = const 7_i32;
use std::intrinsics::mir::*; use std::intrinsics::mir::*;
mir!( mir! {
let x: i32; let x: i32;
let y: i32; let y: i32;
{ {
@ -774,7 +774,7 @@ fn maybe_dead(m: bool) {
retblock = { retblock = {
Return() Return()
} }
) }
} }
fn mut_raw_then_mut_shr() -> (i32, i32) { fn mut_raw_then_mut_shr() -> (i32, i32) {

View File

@ -19,7 +19,7 @@ pub fn f() -> usize {
// CHECK-NOT: goto // CHECK-NOT: goto
// CHECK: switchInt( // CHECK: switchInt(
// CHECK-NOT: goto // CHECK-NOT: goto
mir!( mir! {
let a: isize; let a: isize;
let e: E<char>; let e: E<char>;
{ {
@ -39,7 +39,7 @@ pub fn f() -> usize {
RET = 1; RET = 1;
Return() Return()
} }
) }
} }
// EMIT_MIR set_no_discriminant.generic.JumpThreading.diff // EMIT_MIR set_no_discriminant.generic.JumpThreading.diff
@ -49,7 +49,7 @@ pub fn generic<T>() -> usize {
// CHECK-NOT: goto // CHECK-NOT: goto
// CHECK: switchInt( // CHECK: switchInt(
// CHECK-NOT: goto // CHECK-NOT: goto
mir!( mir! {
let a: isize; let a: isize;
let e: E<T>; let e: E<T>;
{ {
@ -69,7 +69,7 @@ pub fn generic<T>() -> usize {
RET = 1; RET = 1;
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -24,7 +24,7 @@ pub unsafe fn assert_nonzero_nonmax(x: u8) -> u8 {
// CHECK-NEXT: _0 = _1; // CHECK-NEXT: _0 = _1;
// CHECK-NEXT: return; // CHECK-NEXT: return;
// CHECK-NEXT: } // CHECK-NEXT: }
mir!( mir! {
{ {
match x { match x {
0 => unreachable, 0 => unreachable,
@ -48,5 +48,5 @@ pub unsafe fn assert_nonzero_nonmax(x: u8) -> u8 {
RET = x; RET = x;
Return() Return()
} }
) }
} }

View File

@ -8,7 +8,7 @@ use std::intrinsics::mir::*;
// EMIT_MIR switch_to_self.test.MatchBranchSimplification.diff // EMIT_MIR switch_to_self.test.MatchBranchSimplification.diff
#[custom_mir(dialect = "runtime", phase = "post-cleanup")] #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
pub fn test(x: bool) { pub fn test(x: bool) {
mir!( mir! {
{ {
Goto(bb0) Goto(bb0)
} }
@ -18,5 +18,5 @@ pub fn test(x: bool) {
bb1 = { bb1 = {
match x { false => bb0, _ => bb1 } match x { false => bb0, _ => bb1 }
} }
) }
} }

View File

@ -9,11 +9,11 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn main() { pub fn main() {
mir!( mir! {
let a: [u8; 1024]; let a: [u8; 1024];
{ {
a = a; a = a;
Return() Return()
} }
) }
} }

View File

@ -9,7 +9,7 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn main() { pub fn main() {
mir!( mir! {
let a: [u8; 1024]; let a: [u8; 1024];
{ {
Call(a = f(Move(a)), ReturnTo(bb1), UnwindUnreachable()) Call(a = f(Move(a)), ReturnTo(bb1), UnwindUnreachable())
@ -17,7 +17,7 @@ pub fn main() {
bb1 = { bb1 = {
Return() Return()
} }
) }
} }
pub fn f<T: Copy>(a: T) -> T { a } pub fn f<T: Copy>(a: T) -> T { a }

View File

@ -8,7 +8,7 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn f(a: bool) { pub fn f(a: bool) {
mir!( mir! {
let b: (); let b: ();
{ {
match a { true => bb1, _ => bb2 } match a { true => bb1, _ => bb2 }
@ -26,5 +26,5 @@ pub fn f(a: bool) {
StorageDead(b); StorageDead(b);
Return() Return()
} }
) }
} }

View File

@ -15,14 +15,14 @@ use core::ptr::{addr_of, addr_of_mut};
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn multiple_storage() { fn multiple_storage() {
mir!( mir! {
let a: usize; let a: usize;
{ {
StorageLive(a); StorageLive(a);
StorageLive(a); StorageLive(a);
Return() Return()
} }
) }
} }
fn main() { fn main() {

View File

@ -8,12 +8,12 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
fn main() { fn main() {
mir!( mir! {
let a: (); let a: ();
{ {
StorageLive(a); StorageLive(a);
RET = a; RET = a;
Return() Return()
} }
) }
} }

View File

@ -5,7 +5,7 @@ use std::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn f(a: u32) -> u32 { pub fn f(a: u32) -> u32 {
mir!( mir! {
let x: u32; let x: u32;
{ {
// Previously code generation failed with ICE "use of .. before def ..." because the // Previously code generation failed with ICE "use of .. before def ..." because the
@ -15,5 +15,5 @@ pub fn f(a: u32) -> u32 {
RET = x; RET = x;
Return() Return()
} }
) }
} }

View File

@ -10,7 +10,7 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
pub fn f() -> u32 { pub fn f() -> u32 {
mir!( mir! {
let a: u32; let a: u32;
{ {
Call(a = g(), ReturnTo(bb1), UnwindCleanup(bb2)) Call(a = g(), ReturnTo(bb1), UnwindCleanup(bb2))
@ -23,7 +23,7 @@ pub fn f() -> u32 {
RET = a; RET = a;
UnwindResume() UnwindResume()
} }
) }
} }
#[inline(never)] #[inline(never)]

View File

@ -12,7 +12,7 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")] #[custom_mir(dialect = "runtime", phase = "optimized")]
#[inline(always)] #[inline(always)]
pub fn f(a: u32) -> u32 { pub fn f(a: u32) -> u32 {
mir!( mir! {
{ {
match a { match a {
0 => bb1, 0 => bb1,
@ -27,5 +27,5 @@ pub fn f(a: u32) -> u32 {
RET = 2; RET = 2;
Return() Return()
} }
) }
} }

View File

@ -9,13 +9,12 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn main() { pub fn main() {
mir!( mir! {
{ {
Call(RET = main(), ReturnTo(block), UnwindCleanup(block)) Call(RET = main(), ReturnTo(block), UnwindCleanup(block))
} }
block = { block = {
Return() Return()
} }
) }
} }

View File

@ -9,9 +9,9 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn main() { pub fn main() {
mir!( mir! {
{ {
UnwindResume() UnwindResume()
} }
) }
} }

View File

@ -9,9 +9,9 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "built")] #[custom_mir(dialect = "built")]
pub fn main() { pub fn main() {
mir!( mir! {
{ {
UnwindTerminate(ReasonAbi) UnwindTerminate(ReasonAbi)
} }
) }
} }