Auto merge of #125912 - nnethercote:rustfmt-tests-mir-opt, r=oli-obk

rustfmt `tests/mir-opt`

Continuing the work started in #125759. Details in individual commit log messages.

r? `@oli-obk`
This commit is contained in:
bors 2024-06-03 10:25:12 +00:00
commit 8768db9912
112 changed files with 630 additions and 563 deletions

View File

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

View File

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

View File

@ -10,17 +10,13 @@ ignore = [
"/build-*/",
"/vendor/",
# Some tests are not formatted, for multiple reasons:
# - some contain syntax errors that cause rustfmt to give an error
# - some UI tests are broken by different formatting
# - some require special comments in a particular position (e.g. `EMIT_MIR` comments)
# Some tests are not formatted, for various reasons.
"/tests/codegen/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
"/tests/crashes/", # Many tests contain syntax errors.
"/tests/debuginfo/", # Tests are somewhat sensitive to source code layout.
"/tests/incremental/", # Tests are somewhat sensitive to source code layout.
"/tests/mir-opt/",
"/tests/crashes/", # Many of these tests contain syntax errors.
"/tests/debuginfo/", # These tests are somewhat sensitive to source code layout.
"/tests/incremental/", # These tests are somewhat sensitive to source code layout.
"/tests/pretty/",
"/tests/run-make/translation/test.rs", # Contains syntax errors.
"/tests/run-make/translation/test.rs", # This test contains syntax errors.
"/tests/run-make-fulldeps/",
"/tests/run-pass-valgrind/",
"/tests/rustdoc/",

View File

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

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_slice_data.rs:LL:CC
|
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ 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: 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")]
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
mir!({
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
})
mir! {
{
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
}
}
}
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
--> $DIR/ptr_metadata_uninit_slice_len.rs:LL:CC
|
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ 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: 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")]
pub unsafe fn deref_meta(p: *const *const i32) -> () {
mir!({
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
})
mir! {
{
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
}
}
}
fn main() {

View File

@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_thin.rs:LL:CC
|
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ 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: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

View File

@ -9,7 +9,7 @@ fn address_of_reborrow() {
y as *const [i32; 10];
y as *const dyn Send;
y as *const [i32];
y as *const i32; // This is a cast, not a coercion
y as *const i32; // This is a cast, not a coercion
let p: *const _ = y;
let p: *const [i32; 10] = y;

View File

@ -9,7 +9,6 @@ unsafe fn foo(z: *mut usize) -> u32 {
99
}
// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
// CHECK-LABEL: fn main(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,21 +5,24 @@
// EMIT_MIR enum_cast.far.built.after.mir
enum Foo {
A
A,
}
enum Bar {
A, B
A,
B,
}
#[repr(u8)]
enum Boo {
A, B
A,
B,
}
#[repr(i16)]
enum Far {
A, B
A,
B,
}
fn foo(foo: Foo) -> usize {
@ -40,7 +43,9 @@ fn far(far: Far) -> isize {
// EMIT_MIR enum_cast.droppy.built.after.mir
enum Droppy {
A, B, C
A,
B,
C,
}
impl Drop for Droppy {
@ -82,12 +87,15 @@ fn unsigny(x: UnsignedAroundZero) -> u16 {
x as u16
}
enum NotStartingAtZero { A = 4, B = 6, C = 8 }
enum NotStartingAtZero {
A = 4,
B = 6,
C = 8,
}
// EMIT_MIR enum_cast.offsetty.built.after.mir
fn offsetty(x: NotStartingAtZero) -> u32 {
x as u32
}
fn main() {
}
fn main() {}

View File

@ -30,9 +30,13 @@ fn test_or() {
// EMIT_MIR logical_or_in_conditional.test_complex.built.after.mir
fn test_complex() {
if let E::A(_) = E::f() && ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1) {}
if let E::A(_) = E::f()
&& ((always_true() && Droppy(0).0 > 0) || Droppy(1).0 > 1)
{}
if !always_true() && let E::B = E::f() {}
if !always_true()
&& let E::B = E::f()
{}
}
fn main() {

View File

@ -1,7 +1,6 @@
// skip-filecheck
// Test that we don't generate unnecessarily large MIR for very simple matches
// EMIT_MIR simple_match.match_bool.built.after.mir
fn match_bool(x: bool) -> usize {
match x {

View File

@ -3,19 +3,12 @@
// EMIT_MIR shifts.shift_signed.built.after.mir
fn shift_signed(small: i8, big: u128, a: i8, b: i32, c: i128) -> ([i8; 3], [u128; 3]) {
(
[small >> a, small >> b, small >> c],
[big << a, big << b, big << c],
)
([small >> a, small >> b, small >> c], [big << a, big << b, big << c])
}
// EMIT_MIR shifts.shift_unsigned.built.after.mir
fn shift_unsigned(small: u8, big: i128, a: u8, b: u32, c: u128) -> ([u8; 3], [i128; 3]) {
(
[small >> a, small >> b, small >> c],
[big << a, big << b, big << c],
)
([small >> a, small >> b, small >> c], [big << a, big << b, big << c])
}
fn main() {
}
fn main() {}

View File

@ -3,6 +3,7 @@
// generate `StorageStart` or `StorageEnd` statements.
// EMIT_MIR storage_live_dead_in_statics.XXX.built.after.mir
#[rustfmt::skip]
static XXX: &'static Foo = &Foo {
tup: "hi",
data: &[
@ -20,13 +21,13 @@ static XXX: &'static Foo = &Foo {
(0, 1), (0, 2), (0, 3),
(0, 1), (0, 2), (0, 3),
(0, 1), (0, 2), (0, 3),
]
],
};
#[derive(Debug)]
struct Foo {
tup: &'static str,
data: &'static [(u32, u32)]
data: &'static [(u32, u32)],
}
fn main() {

View File

@ -11,7 +11,7 @@ impl<This> NeedsDrop for This {}
// EMIT_MIR control_flow_simplification.hello.GVN.diff
// EMIT_MIR control_flow_simplification.hello.PreCodegen.before.mir
fn hello<T>(){
fn hello<T>() {
if <bool>::NEEDS {
panic!()
}

View File

@ -8,7 +8,11 @@
#[derive(Copy, Clone)]
#[repr(u32)]
enum E { A, B, C }
enum E {
A,
B,
C,
}
#[derive(Copy, Clone)]
enum Empty {}
@ -39,7 +43,5 @@ fn main() {
// A non-UTF-8 string slice. Regression test for #75763 and #78520.
struct Str<const S: &'static str>;
let _non_utf8_str: Str::<{
unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) }
}>;
let _non_utf8_str: Str<{ unsafe { std::mem::transmute::<&[u8], &str>(&[0xC0, 0xC1, 0xF5]) } }>;
}

View File

@ -31,7 +31,7 @@ struct Delta<T> {
enum Epsilon {
A(u8, u16),
B,
C { c: u32 }
C { c: u32 },
}
enum Zeta<T> {

View File

@ -2,7 +2,7 @@
//@ test-mir-pass: GVN
#[inline(never)]
fn read(_: usize) { }
fn read(_: usize) {}
// EMIT_MIR pointer_expose_provenance.main.GVN.diff
fn main() {

View File

@ -10,4 +10,4 @@ fn main() {
}
#[inline(never)]
fn consume(_: u32) { }
fn consume(_: u32) {}

View File

@ -3,7 +3,7 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
#[inline(never)]
fn foo(_: i32) { }
fn foo(_: i32) {}
// EMIT_MIR switch_int.main.GVN.diff
// EMIT_MIR switch_int.main.SimplifyConstCondition-after-const-prop.diff

View File

@ -45,7 +45,10 @@ pub unsafe fn undef_union_as_integer() -> u32 {
// CHECK-LABEL: fn undef_union_as_integer(
// CHECK: _1 = Union32 {
// CHECK: _0 = move _1 as u32 (Transmute);
union Union32 { value: u32, unit: () }
union Union32 {
value: u32,
unit: (),
}
unsafe { transmute(Union32 { unit: () }) }
}

View File

@ -10,4 +10,4 @@ fn main() {
}
#[inline(never)]
fn consume(_: (u32, u32)) { }
fn consume(_: (u32, u32)) {}

View File

@ -4,10 +4,12 @@
#![feature(custom_mir, core_intrinsics, freeze)]
#![allow(unused_assignments)]
extern crate core;
use core::marker::Freeze;
use core::intrinsics::mir::*;
use core::marker::Freeze;
fn opaque(_: impl Sized) -> bool { true }
fn opaque(_: impl Sized) -> bool {
true
}
fn cmp_ref(a: &u8, b: &u8) -> bool {
std::ptr::eq(a as *const u8, b as *const u8)
@ -24,7 +26,7 @@ fn compare_address() -> bool {
// CHECK-NEXT: _0 = cmp_ref(_2, _4)
// CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<u8>(_3)
mir!(
mir! {
{
let a = 5_u8;
let r1 = &a;
@ -40,7 +42,7 @@ fn compare_address() -> bool {
ret = {
Return()
}
)
}
}
/// Generic type `T` is `Freeze`, so shared borrows are immutable.
@ -52,7 +54,7 @@ fn borrowed<T: Copy + Freeze>(x: T) -> bool {
// CHECK-NEXT: _0 = opaque::<&T>(_3)
// CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<T>(_1)
mir!(
mir! {
{
let a = x;
let r1 = &x;
@ -64,7 +66,7 @@ fn borrowed<T: Copy + Freeze>(x: T) -> bool {
ret = {
Return()
}
)
}
}
/// Generic type `T` is not known to be `Freeze`, so shared borrows may be mutable.
@ -77,7 +79,7 @@ fn non_freeze<T: Copy>(x: T) -> bool {
// CHECK-NEXT: _0 = opaque::<&T>(_3)
// CHECK: bb1: {
// CHECK-NEXT: _0 = opaque::<T>(_2)
mir!(
mir! {
{
let a = x;
let r1 = &x;
@ -89,7 +91,7 @@ fn non_freeze<T: Copy>(x: T) -> bool {
ret = {
Return()
}
)
}
}
fn main() {

View File

@ -12,17 +12,19 @@ struct NotCopy(bool);
// EMIT_MIR custom_move_arg.f.CopyProp.diff
#[custom_mir(dialect = "runtime")]
fn f(_1: NotCopy) {
mir!({
let _2 = _1;
Call(RET = opaque(Move(_1)), ReturnTo(bb1), UnwindUnreachable())
mir! {
{
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)]

View File

@ -7,13 +7,15 @@
extern crate core;
use core::intrinsics::mir::*;
fn opaque(_: impl Sized) -> bool { true }
fn opaque(_: impl Sized) -> bool {
true
}
struct Foo(u8);
#[custom_mir(dialect = "runtime")]
fn f(a: Foo) -> bool {
mir!(
mir! {
{
let b = a;
// This is a move out of a copy, so must become a copy of `a.0`.
@ -26,7 +28,7 @@ fn f(a: Foo) -> bool {
ret = {
Return()
}
)
}
}
fn main() {

View File

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

View File

@ -8,16 +8,28 @@ use core::intrinsics::mir::*;
#[custom_mir(dialect = "analysis", phase = "post-cleanup")]
fn f(c: bool) -> bool {
mir!(
mir! {
let a: 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`.
// It should not be replaced by `b`.
bb2 = { a = b; c = false; Goto(bb1) }
bb3 = { RET = a; Return() }
)
bb2 = {
a = b;
c = false;
Goto(bb1)
}
bb3 = {
RET = a;
Return()
}
}
}
fn main() {

View File

@ -8,7 +8,7 @@ use std::intrinsics::mir::*;
#[derive(Copy, Clone)]
enum E {
V1(i32),
V2(i32)
V2(i32),
}
// EMIT_MIR enum.simple.DataflowConstProp.diff
@ -23,7 +23,10 @@ fn simple() {
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
// CHECK: [[target_bb]]: {
// CHECK: [[x]] = const 0_i32;
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
let x = match e {
E::V1(x1) => x1,
E::V2(x2) => x2,
};
}
// EMIT_MIR enum.constant.DataflowConstProp.diff
@ -39,7 +42,10 @@ fn constant() {
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
// CHECK: [[target_bb]]: {
// CHECK: [[x]] = const 0_i32;
let x = match e { E::V1(x1) => x1, E::V2(x2) => x2 };
let x = match e {
E::V1(x1) => x1,
E::V2(x2) => x2,
};
}
// EMIT_MIR enum.statics.DataflowConstProp.diff
@ -58,7 +64,10 @@ fn statics() {
// CHECK: switchInt(const 0_isize) -> [0: [[target_bb:bb.*]], 1: bb2, otherwise: bb1];
// CHECK: [[target_bb]]: {
// CHECK: [[x1]] = const 0_i32;
let x1 = match e1 { E::V1(x11) => x11, E::V2(x12) => x12 };
let x1 = match e1 {
E::V1(x11) => x11,
E::V2(x12) => x12,
};
static RC: &E = &E::V2(4);
@ -72,7 +81,10 @@ fn statics() {
// One is `_9 = &(*_12) and another is `_9 = _11`. It is different from what we can
// get by printing MIR directly. It is better to check if there are any bugs in the
// MIR passes around this stage.
let x2 = match e2 { E::V1(x21) => x21, E::V2(x22) => x22 };
let x2 = match e2 {
E::V1(x21) => x21,
E::V2(x22) => x22,
};
}
#[rustc_layout_scalar_valid_range_start(1)]
@ -84,7 +96,7 @@ struct NonZeroUsize(usize);
// CHECK-LABEL: fn mutate_discriminant(
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn mutate_discriminant() -> u8 {
mir!(
mir! {
let x: Option<NonZeroUsize>;
{
SetDiscriminant(x, 1);
@ -109,7 +121,7 @@ fn mutate_discriminant() -> u8 {
RET = 2;
Unreachable()
}
)
}
}
// EMIT_MIR enum.multiple.DataflowConstProp.diff
@ -132,7 +144,10 @@ fn multiple(x: bool, i: u8) {
// CHECK: [[x2]] = const 0_u8;
// CHECK: [[some:_.*]] = (({{_.*}} as Some).0: u8)
// CHECK: [[x2]] = [[some]];
let x2 = match e { Some(i) => i, None => 0 };
let x2 = match e {
Some(i) => i,
None => 0,
};
// Therefore, `x2` should be `Top` here, and no replacement shall happen.

View File

@ -2,9 +2,9 @@
// EMIT_MIR mult_by_zero.test.DataflowConstProp.diff
// CHECK-LABEL: fn test(
fn test(x : i32) -> i32 {
x * 0
// CHECK: _0 = const 0_i32;
fn test(x: i32) -> i32 {
x * 0
// CHECK: _0 = const 0_i32;
}
fn main() {

View File

@ -45,7 +45,10 @@ pub unsafe fn undef_union_as_integer() -> u32 {
// CHECK-LABEL: fn undef_union_as_integer(
// CHECK: _1 = Union32 {
// CHECK: _0 = move _1 as u32 (Transmute);
union Union32 { value: u32, unit: () }
union Union32 {
value: u32,
unit: (),
}
unsafe { transmute(Union32 { unit: () }) }
}

View File

@ -29,7 +29,7 @@ struct Packed {
fn move_packed(packed: Packed) {
// CHECK-LABEL: fn move_packed(
// 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.
Call(RET = use_both(0, packed.y), ReturnTo(ret), UnwindContinue())
@ -37,7 +37,7 @@ fn move_packed(packed: Packed) {
ret = {
Return()
}
)
}
}
fn main() {

View File

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

View File

@ -4,5 +4,7 @@
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
fn main() {
for &foo in &[42, 43] { drop(foo) }
for &foo in &[42, 43] {
drop(foo)
}
}

View File

@ -7,7 +7,9 @@ fn main() {
let b = foo();
let d = foo();
match ****(&&&&b) {
true => {let x = 5;},
true => {
let x = 5;
}
false => {}
}
let y = 42;

View File

@ -2,7 +2,7 @@
//@ test-mir-pass: Derefer
// EMIT_MIR derefer_test.main.Derefer.diff
fn main() {
let mut a = (42,43);
let mut a = (42, 43);
let mut b = (99, &mut a);
let x = &mut (*b.1).0;
let y = &mut (*b.1).1;

View File

@ -1,7 +1,7 @@
// skip-filecheck
//@ test-mir-pass: Derefer
// EMIT_MIR derefer_test_multiple.main.Derefer.diff
fn main () {
fn main() {
let mut a = (42, 43);
let mut b = (99, &mut a);
let mut c = (11, &mut b);

View File

@ -7,22 +7,22 @@
// Tests that an enum with a variant with no data gets correctly transformed.
pub enum NoData {
Large([u8; 8196]),
None,
Large([u8; 8196]),
None,
}
// Tests that an enum with a variant with data that is a valid candidate gets transformed.
pub enum Candidate {
Small(u8),
Large([u8; 8196]),
Small(u8),
Large([u8; 8196]),
}
// Tests that an enum which has a discriminant much higher than the variant does not get
// tformed.
#[repr(u32)]
pub enum InvalidIdxs {
A = 302,
Large([u64; 1024]),
A = 302,
Large([u64; 1024]),
}
// Tests that an enum with too high of a discriminant index (not in bounds of usize) does not
@ -37,51 +37,51 @@ pub enum NotTrunctable {
// Tests that an enum with discriminants in random order still gets tformed correctly.
#[repr(u32)]
pub enum RandOrderDiscr {
A = 13,
B([u8; 1024]) = 5,
C = 7,
A = 13,
B([u8; 1024]) = 5,
C = 7,
}
// EMIT_MIR enum_opt.unin.EnumSizeOpt.diff
pub fn unin() -> NoData {
let mut a = NoData::None;
a = NoData::Large([1; 8196]);
a
let mut a = NoData::None;
a = NoData::Large([1; 8196]);
a
}
// EMIT_MIR enum_opt.cand.EnumSizeOpt.diff
pub fn cand() -> Candidate {
let mut a = Candidate::Small(1);
a = Candidate::Large([1; 8196]);
a
let mut a = Candidate::Small(1);
a = Candidate::Large([1; 8196]);
a
}
// EMIT_MIR enum_opt.invalid.EnumSizeOpt.diff
pub fn invalid() -> InvalidIdxs {
let mut a = InvalidIdxs::A;
a = InvalidIdxs::Large([0; 1024]);
a
let mut a = InvalidIdxs::A;
a = InvalidIdxs::Large([0; 1024]);
a
}
// EMIT_MIR enum_opt.trunc.EnumSizeOpt.diff
pub fn trunc() -> NotTrunctable {
let mut a = NotTrunctable::A;
a = NotTrunctable::B([0; 1024]);
a = NotTrunctable::C([0; 4096]);
a
let mut a = NotTrunctable::A;
a = NotTrunctable::B([0; 1024]);
a = NotTrunctable::C([0; 4096]);
a
}
pub fn rand_order() -> RandOrderDiscr {
let mut a = RandOrderDiscr::A;
a = RandOrderDiscr::B([0; 1024]);
a = RandOrderDiscr::C;
a
let mut a = RandOrderDiscr::A;
a = RandOrderDiscr::B([0; 1024]);
a = RandOrderDiscr::C;
a
}
pub fn main() {
unin();
cand();
invalid();
trunc();
rand_order();
unin();
cand();
invalid();
trunc();
rand_order();
}

View File

@ -539,7 +539,7 @@ fn slices() {
#[custom_mir(dialect = "analysis")]
fn duplicate_slice() -> (bool, bool) {
// CHECK-LABEL: fn duplicate_slice(
mir!(
mir! {
let au: u128;
let bu: u128;
let cu: u128;
@ -585,7 +585,7 @@ fn duplicate_slice() -> (bool, bool) {
RET = (direct, indirect);
Return()
}
)
}
}
fn repeat() {
@ -623,11 +623,13 @@ fn fn_pointers() {
fn indirect_static() {
static A: Option<u8> = None;
mir!({
let ptr = Static(A);
let out = Field::<u8>(Variant(*ptr, 1), 0);
Return()
})
mir! {
{
let ptr = Static(A);
let out = Field::<u8>(Variant(*ptr, 1), 0);
Return()
}
}
}
/// 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: bb2: {
// CHECK-NEXT: _0 = opaque::<T>(_1)
mir!(
mir! {
{
let a = x;
let r1 = &x;
@ -748,7 +750,7 @@ fn borrowed<T: Copy + Freeze>(x: T) {
ret = {
Return()
}
)
}
}
/// 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: bb2: {
// CHECK-NEXT: _0 = opaque::<T>((*_3))
mir!(
mir! {
{
let a = x;
let r1 = &x;
@ -778,7 +780,7 @@ fn non_freeze<T: Copy>(x: T) {
ret = {
Return()
}
)
}
}
fn main() {

View File

@ -32,7 +32,6 @@ impl<T: Call> Call for A<T> {
}
}
impl<T: Call> Call for B<T> {
#[inline]
fn call() {

View File

@ -26,7 +26,6 @@ impl Call for A {
}
}
impl<T: Call> Call for B<T> {
#[inline]
fn call() {

View File

@ -16,8 +16,16 @@ fn main() {
// Cost is approximately 3 * 25 + 5 = 80.
#[inline]
pub fn not_inlined() { g(); g(); g(); }
pub fn inlined<T>() { g(); g(); g(); }
pub fn not_inlined() {
g();
g();
g();
}
pub fn inlined<T>() {
g();
g();
g();
}
#[inline(never)]
fn g() {}

View File

@ -5,7 +5,7 @@
fn main() {
// CHECK-LABEL: fn main(
// CHECK: (inlined <Vec<()> as Foo>::bar)
let x = <Vec::<()> as Foo>::bar();
let x = <Vec<()> as Foo>::bar();
}
trait Foo {
@ -14,5 +14,7 @@ trait Foo {
impl<T> Foo for Vec<T> {
#[inline(always)]
default fn bar() -> u32 { 123 }
default fn bar() -> u32 {
123
}
}

View File

@ -19,11 +19,7 @@ fn inner() -> usize {
// CHECK: = {{.*}}[_0];
let buffer = &[true];
let index = index();
if buffer[index] {
index
} else {
0
}
if buffer[index] { index } else { 0 }
}
fn main() {

View File

@ -13,6 +13,9 @@ fn main() {
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
let f = |x| { let y = x; y };
let f = |x| {
let y = x;
y
};
f(())
}

View File

@ -7,9 +7,9 @@ fn norm2(x: [f32; 2]) -> f32 {
// CHECK-NOT: Len(
let a = x[0];
let b = x[1];
a*a + b*b
a * a + b * b
}
fn main() {
assert_eq!(norm2([3.0, 4.0]), 5.0*5.0);
assert_eq!(norm2([3.0, 4.0]), 5.0 * 5.0);
}

View File

@ -5,7 +5,7 @@
#![feature(custom_mir)]
use std::intrinsics::mir::*;
use std::mem::{MaybeUninit, ManuallyDrop, transmute};
use std::mem::{transmute, ManuallyDrop, MaybeUninit};
// EMIT_MIR combine_transmutes.identity_transmutes.InstSimplify.diff
pub unsafe fn identity_transmutes() {
@ -61,4 +61,7 @@ pub unsafe fn adt_transmutes() {
let _a: ManuallyDrop<String> = transmute(MaybeUninit::<String>::uninit());
}
pub union Union32 { u32: u32, i32: i32 }
pub union Union32 {
u32: u32,
i32: i32,
}

View File

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

View File

@ -5,9 +5,7 @@
// EMIT_MIR issue_104451_unwindable_intrinsics.main.AbortUnwindingCalls.after.mir
fn main() {
unsafe {
core::intrinsics::const_eval_select((), ow_ct, ow_ct)
}
unsafe { core::intrinsics::const_eval_select((), ow_ct, ow_ct) }
}
const fn ow_ct() -> ! {

View File

@ -3,7 +3,6 @@
// check that we don't emit multiple drop flags when they are not needed.
// EMIT_MIR issue_41110.main.ElaborateDrops.diff
fn main() {
let x = S.other(S.id());
@ -21,11 +20,12 @@ pub fn test() {
struct S;
impl Drop for S {
fn drop(&mut self) {
}
fn drop(&mut self) {}
}
impl S {
fn id(self) -> Self { self }
fn id(self) -> Self {
self
}
fn other(self, s: Self) {}
}

View File

@ -14,9 +14,8 @@ trait Foo {
fn get(&self) -> [u8; 2];
}
// EMIT_MIR issue_41697.{impl#0}-{constant#0}.SimplifyCfg-promote-consts.after.mir
impl Foo for [u8; 1+1] {
impl Foo for [u8; 1 + 1] {
fn get(&self) -> [u8; 2] {
*self
}
@ -33,7 +32,7 @@ fn unsize_nested_fat_ptr(x: Arc<Foo + Send>) -> Arc<Foo> {
}
fn main() {
let x: Box<Bar<Foo + Send>> = Box::new(Bar([1,2]));
let x: Box<Bar<Foo + Send>> = Box::new(Bar([1, 2]));
assert_eq!(unsize_fat_ptr(&*x).0.get(), [1, 2]);
let x: Arc<Foo + Send> = Arc::new([3, 4]);

View File

@ -1,6 +1,6 @@
// MIR for `<impl at $DIR/issue_41697.rs:19:1: 19:23>::{constant#0}` after SimplifyCfg-promote-consts
// MIR for `<impl at $DIR/issue_41697.rs:18:1: 18:25>::{constant#0}` after SimplifyCfg-promote-consts
<impl at $DIR/issue_41697.rs:19:1: 19:23>::{constant#0}: usize = {
<impl at $DIR/issue_41697.rs:18:1: 18:25>::{constant#0}: usize = {
let mut _0: usize;
let mut _1: (usize, bool);

View File

@ -15,11 +15,13 @@ fn main() {
}
}
fn cond() -> bool { false }
fn cond() -> bool {
false
}
struct K;
enum E {
F(K),
G(Box<E>)
G(Box<E>),
}

View File

@ -9,16 +9,18 @@ enum Never {}
union Foo {
a: u64,
b: Never
b: Never,
}
// EMIT_MIR issue_72181.foo.built.after.mir
fn foo(xs: [(Never, u32); 1]) -> u32 { xs[0].1 }
fn foo(xs: [(Never, u32); 1]) -> u32 {
xs[0].1
}
// EMIT_MIR issue_72181.bar.built.after.mir
fn bar([(_, x)]: [(Never, u32); 1]) -> u32 { x }
fn bar([(_, x)]: [(Never, u32); 1]) -> u32 {
x
}
// EMIT_MIR issue_72181.main.built.after.mir
fn main() {

View File

@ -14,9 +14,7 @@ fn f(v: Void) -> ! {
// EMIT_MIR issue_72181_1.main.built.after.mir
fn main() {
let v: Void = unsafe {
std::mem::transmute::<(), Void>(())
};
let v: Void = unsafe { std::mem::transmute::<(), Void>(()) };
f(v);
}

View File

@ -1,32 +1,30 @@
// skip-filecheck
//@ compile-flags: -Z mir-opt-level=0
// EMIT_MIR issue_91633.hey.built.after.mir
fn hey<T> (it: &[T])
where
[T] : std::ops::Index<usize>,
{
let _ = &it[0];
}
fn hey<T>(it: &[T])
where
[T]: std::ops::Index<usize>,
{
let _ = &it[0];
}
// EMIT_MIR issue_91633.bar.built.after.mir
fn bar<T> (it: Box<[T]>)
where
[T] : std::ops::Index<usize>,
{
let _ = it[0];
}
fn bar<T>(it: Box<[T]>)
where
[T]: std::ops::Index<usize>,
{
let _ = it[0];
}
// EMIT_MIR issue_91633.fun.built.after.mir
fn fun<T> (it: &[T]) -> &T
{
let f = &it[0];
f
}
fn fun<T>(it: &[T]) -> &T {
let f = &it[0];
f
}
// EMIT_MIR issue_91633.foo.built.after.mir
fn foo<T: Clone> (it: Box<[T]>) -> T
{
let f = it[0].clone();
f
}
fn main(){}
fn foo<T: Clone>(it: Box<[T]>) -> T {
let f = it[0].clone();
f
}
fn main() {}

View File

@ -8,11 +8,7 @@ pub fn foo(bytes: [u8; 16]) -> Option<[u8; 4]> {
// big endian `u32`s
let dwords: [u32; 4] = unsafe { transmute(bytes) };
const FF: u32 = 0x0000_ffff_u32.to_be();
if let [0, 0, 0 | FF, ip] = dwords {
Some(unsafe { transmute(ip) })
} else {
None
}
if let [0, 0, 0 | FF, ip] = dwords { Some(unsafe { transmute(ip) }) } else { None }
}
fn main() {

View File

@ -157,7 +157,7 @@ fn custom_discr(x: bool) -> u8 {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn multiple_match(x: u8) -> u8 {
// CHECK-LABEL: fn multiple_match(
mir!(
mir! {
{
// CHECK: bb0: {
// CHECK: switchInt([[x:_.*]]) -> [3: bb1, otherwise: bb2];
@ -220,7 +220,7 @@ fn multiple_match(x: u8) -> u8 {
RET = 11;
Return()
}
)
}
}
/// 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")]
fn duplicate_chain(x: bool) -> u8 {
// CHECK-LABEL: fn duplicate_chain(
mir!(
mir! {
let a: u8;
{
// CHECK: bb0: {
@ -278,7 +278,7 @@ fn duplicate_chain(x: bool) -> u8 {
RET = 9;
Return()
}
)
}
}
#[rustc_layout_scalar_valid_range_start(1)]
@ -292,7 +292,7 @@ fn mutate_discriminant() -> u8 {
// CHECK-NOT: goto -> {{bb.*}};
// CHECK: switchInt(
// CHECK-NOT: goto -> {{bb.*}};
mir!(
mir! {
let x: Option<NonZeroUsize>;
{
SetDiscriminant(x, 1);
@ -313,7 +313,7 @@ fn mutate_discriminant() -> u8 {
RET = 2;
Unreachable()
}
)
}
}
/// Verify that we do not try to reason when there are mutable pointers involved.
@ -330,11 +330,7 @@ fn mutable_ref() -> bool {
let a = std::ptr::addr_of_mut!(x);
x = 7;
unsafe { *a = 8 };
if x == 7 {
true
} else {
false
}
if x == 7 { true } else { false }
}
/// This function has 2 TOs: 1-3-4 and 0-1-3-4-6.
@ -342,7 +338,7 @@ fn mutable_ref() -> bool {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn renumbered_bb(x: bool) -> u8 {
// CHECK-LABEL: fn renumbered_bb(
mir!(
mir! {
let a: bool;
let b: bool;
{
@ -398,7 +394,7 @@ fn renumbered_bb(x: bool) -> u8 {
// Duplicate of bb4.
// CHECK: bb9: {
// CHECK-NEXT: goto -> bb6;
)
}
}
/// This function has 3 TOs: 1-4-5, 0-1-4-7-5-8 and 3-4-7-5-6
@ -408,7 +404,7 @@ fn renumbered_bb(x: bool) -> u8 {
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn disappearing_bb(x: u8) -> u8 {
// CHECK-LABEL: fn disappearing_bb(
mir!(
mir! {
let a: bool;
let b: bool;
{
@ -450,7 +446,7 @@ fn disappearing_bb(x: u8) -> u8 {
// CHECK: goto -> bb5;
// CHECK: bb10: {
// CHECK: goto -> bb6;
)
}
}
/// Verify that we can thread jumps when we assign from an aggregate constant.
@ -461,18 +457,14 @@ fn aggregate(x: u8) -> u8 {
const FOO: (u8, u8) = (5, 13);
let (a, b) = FOO;
if a == 7 {
b
} else {
a
}
if a == 7 { b } else { a }
}
/// Verify that we can leverage the existence of an `Assume` terminator.
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
fn assume(a: u8, b: bool) -> u8 {
// CHECK-LABEL: fn assume(
mir!(
mir! {
{
// CHECK: bb0: {
// CHECK-NEXT: switchInt(_1) -> [7: bb1, otherwise: bb2]
@ -511,7 +503,7 @@ fn assume(a: u8, b: bool) -> u8 {
}
// CHECK: bb6: {
// CHECK-NEXT: goto -> bb5;
)
}
}
fn main() {

View File

@ -7,11 +7,7 @@ pub fn array_bound<const N: usize>(index: usize, slice: &[u8; N]) -> u8 {
// CHECK-LABEL: fn array_bound(
// CHECK: [[len:_.*]] = const N;
// CHECK: Lt(move {{_.*}}, move [[len]]);
if index < slice.len() {
slice[index]
} else {
42
}
if index < slice.len() { slice[index] } else { 42 }
}
// EMIT_MIR lower_array_len.array_bound_mut.NormalizeArrayLen.diff

View File

@ -5,11 +5,7 @@
pub fn bound(index: usize, slice: &[u8]) -> u8 {
// CHECK-LABEL: fn bound(
// CHECK-NOT: ::len(
if index < slice.len() {
slice[index]
} else {
42
}
if index < slice.len() { slice[index] } else { 42 }
}
fn main() {

View File

@ -88,7 +88,7 @@ fn match_u8_i16(i: EnumAu8) -> i16 {
fn match_u8_i16_2(i: EnumAu8) -> i16 {
// CHECK-LABEL: fn match_u8_i16_2(
// CHECK: switchInt
mir!(
mir! {
{
let a = Discriminant(i);
match a {
@ -110,7 +110,7 @@ fn match_u8_i16_2(i: EnumAu8) -> i16 {
ret = {
Return()
}
)
}
}
// 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 {
// CHECK-LABEL: fn match_u8_u16_2(
// CHECK: switchInt
mir!(
mir! {
{
let a = Discriminant(i);
match a {
@ -187,7 +187,7 @@ fn match_u8_u16_2(i: EnumBu8) -> i16 {
ret = {
Return()
}
)
}
}
#[repr(i8)]

View File

@ -1,7 +1,6 @@
// skip-filecheck
//@ test-mir-pass: MatchBranchSimplification
// EMIT_MIR matches_u8.exhaustive_match.MatchBranchSimplification.diff
// EMIT_MIR matches_u8.exhaustive_match_i8.MatchBranchSimplification.diff
@ -27,9 +26,9 @@ pub fn exhaustive_match_i8(e: E) -> i8 {
}
fn main() {
assert_eq!(exhaustive_match(E::A), 0);
assert_eq!(exhaustive_match(E::B), 1);
assert_eq!(exhaustive_match(E::A), 0);
assert_eq!(exhaustive_match(E::B), 1);
assert_eq!(exhaustive_match_i8(E::A), 0);
assert_eq!(exhaustive_match_i8(E::B), 1);
assert_eq!(exhaustive_match_i8(E::A), 0);
assert_eq!(exhaustive_match_i8(E::B), 1);
}

View File

@ -10,7 +10,8 @@
#![allow(warnings)]
// EMIT_MIR named_lifetimes_basic.use_x.nll.0.mir
fn use_x<'a, 'b: 'a, 'c>(w: &'a mut i32, x: &'b u32, y: &'a u32, z: &'c u32) -> bool { true }
fn main() {
fn use_x<'a, 'b: 'a, 'c>(w: &'a mut i32, x: &'b u32, y: &'a u32, z: &'c u32) -> bool {
true
}
fn main() {}

View File

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

View File

@ -10,5 +10,7 @@ fn nrvo(init: fn(&mut [u8; 1024])) -> [u8; 1024] {
}
fn main() {
let _ = nrvo(|buf| { buf[4] = 4; });
let _ = nrvo(|buf| {
buf[4] = 4;
});
}

View File

@ -1,7 +1,6 @@
// skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
// EMIT_MIR packed_struct_drop_aligned.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
let mut x = Packed(Aligned(Droppy(0)));

View File

@ -12,7 +12,6 @@ pub fn f_unit() {
f_dispatch(());
}
// EMIT_MIR intrinsics.f_u64.PreCodegen.after.mir
pub fn f_u64() {
f_dispatch(0u64);
@ -28,8 +27,7 @@ pub fn f_dispatch<T>(t: T) {
}
#[inline(never)]
pub fn f_zst<T>(_t: T) {
}
pub fn f_zst<T>(_t: T) {}
#[inline(never)]
pub fn f_non_zst<T>(_t: T) {}

View File

@ -15,5 +15,5 @@ struct Point {
fn main() {
let x = 2 + 2;
let y = [0, 1, 2, 3, 4, 5][3];
let z = (Point { x: 12, y: 42}).y;
let z = (Point { x: 12, y: 42 }).y;
}

View File

@ -17,18 +17,16 @@ fn new<T, E>(x: Result<T, E>) -> Result<T, E> {
} {
ControlFlow::Continue(v) => v,
ControlFlow::Break(e) => return Err(e),
}
},
)
}
// EMIT_MIR try_identity.old.PreCodegen.after.mir
fn old<T, E>(x: Result<T, E>) -> Result<T, E> {
Ok(
match x {
Ok(v) => v,
Err(e) => return Err(e),
}
)
Ok(match x {
Ok(v) => v,
Err(e) => return Err(e),
})
}
fn main() {

View File

@ -658,7 +658,7 @@ fn read_through_raw(x: &mut usize) -> usize {
// CHECK-NEXT: return;
use std::intrinsics::mir::*;
mir!(
mir! {
let r1: &mut usize;
let r2: &mut usize;
let p1: *mut usize;
@ -674,7 +674,7 @@ fn read_through_raw(x: &mut usize) -> usize {
RET = *p2;
Return()
}
)
}
}
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@ -683,7 +683,7 @@ fn multiple_storage() {
// CHECK: _3 = (*_2);
use std::intrinsics::mir::*;
mir!(
mir! {
let x: i32;
{
StorageLive(x);
@ -700,7 +700,7 @@ fn multiple_storage() {
retblock = {
Return()
}
)
}
}
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@ -709,7 +709,7 @@ fn dominate_storage() {
// CHECK: _5 = (*_2);
use std::intrinsics::mir::*;
mir!(
mir! {
let x: i32;
let r: &i32;
let c: i32;
@ -730,7 +730,7 @@ fn dominate_storage() {
let d = true;
match d { false => bb2, _ => bb0 }
}
)
}
}
#[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@ -739,7 +739,7 @@ fn maybe_dead(m: bool) {
// CHECK: (*_5) = const 7_i32;
use std::intrinsics::mir::*;
mir!(
mir! {
let x: i32;
let y: i32;
{
@ -774,7 +774,7 @@ fn maybe_dead(m: bool) {
retblock = {
Return()
}
)
}
}
fn mut_raw_then_mut_shr() -> (i32, i32) {
@ -787,7 +787,9 @@ fn mut_raw_then_mut_shr() -> (i32, i32) {
let xshr = &*xref;
// Verify that we completely replace with `x` in both cases.
let a = *xshr;
unsafe { *xraw = 4; }
unsafe {
*xraw = 4;
}
(a, x)
}
@ -842,8 +844,7 @@ fn debuginfo() {
// `constant_index_from_end` and `subslice` should not be promoted, as their value depends
// on the slice length.
if let [_, ref constant_index, subslice @ .., ref constant_index_from_end] = &[6; 10][..] {
}
if let [_, ref constant_index, subslice @ .., ref constant_index_from_end] = &[6; 10][..] {}
let multiple_borrow = &&&mut T(6).0;
}

View File

@ -59,7 +59,9 @@ pub fn main() {
fn array_casts() {
let mut x: [usize; 2] = [0, 0];
let p = &mut x as *mut usize;
unsafe { *p.add(1) = 1; }
unsafe {
*p.add(1) = 1;
}
let x: [usize; 2] = [0, 1];
let p = &x as *const usize;

View File

@ -2,8 +2,8 @@
// this tests move up progration, which is not yet implemented
fn foo() -> [u8; 1024] {
let x = [0; 1024];
return x;
let x = [0; 1024];
return x;
}
fn main() { }
fn main() {}

View File

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

View File

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

View File

@ -1,13 +1,12 @@
// skip-filecheck
//@ test-mir-pass: SimplifyLocals-before-const-prop
#![feature(thread_local)]
#[derive(Copy, Clone)]
enum E {
A,
B,
A,
B,
}
// EMIT_MIR simplify_locals.c.SimplifyLocals-before-const-prop.diff
@ -26,7 +25,7 @@ fn d1() {
// EMIT_MIR simplify_locals.d2.SimplifyLocals-before-const-prop.diff
fn d2() {
// Unused set discriminant
{(10, E::A)}.1 = E::B;
{ (10, E::A) }.1 = E::B;
}
// EMIT_MIR simplify_locals.r.SimplifyLocals-before-const-prop.diff
@ -37,7 +36,8 @@ fn r() {
let _ = &mut a;
}
#[thread_local] static mut X: u32 = 0;
#[thread_local]
static mut X: u32 = 0;
// EMIT_MIR simplify_locals.t1.SimplifyLocals-before-const-prop.diff
fn t1() {

View File

@ -4,9 +4,7 @@
fn foo<T>() {
if let (Some(a), None) = (Option::<u8>::None, Option::<T>::None) {
if a > 42u8 {
}
if a > 42u8 {}
}
}

View File

@ -5,8 +5,11 @@ fn noop() {}
// EMIT_MIR simplify_match.main.GVN.diff
fn main() {
match { let x = false; x } {
match {
let x = false;
x
} {
true => noop(),
false => {},
false => {}
}
}

View File

@ -19,10 +19,7 @@ fn foo<T: Err>() {
// CHECK-NOT: [foo:_.*]: Foo
// CHECK-NOT: Box<dyn std::fmt::Display + 'static>
let foo: Foo<T> = Foo {
x: Ok(Box::new(5_u32)),
y: 7_u32,
};
let foo: Foo<T> = Foo { x: Ok(Box::new(5_u32)), y: 7_u32 };
let x = foo.x;
let y = foo.y;

View File

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

View File

@ -6,15 +6,15 @@ pub enum Void {}
// EMIT_MIR uninhabited_enum.process_never.SimplifyLocals-final.after.mir
#[no_mangle]
pub fn process_never(input: *const !) {
let _input = unsafe { &*input };
let _input = unsafe { &*input };
}
// EMIT_MIR uninhabited_enum.process_void.SimplifyLocals-final.after.mir
#[no_mangle]
pub fn process_void(input: *const Void) {
let _input = unsafe { &*input };
// In the future, this should end with `unreachable`, but we currently only do
// unreachability analysis for `!`.
let _input = unsafe { &*input };
// In the future, this should end with `unreachable`, but we currently only do
// unreachability analysis for `!`.
}
fn main() {}

View File

@ -17,7 +17,7 @@ struct Foo {
_: struct {
d: [u8; 1],
}
}
},
}
#[repr(C)]
@ -31,10 +31,9 @@ union Bar {
_: union {
d: [u8; 1],
}
}
},
}
fn access<T>(_: T) {}
// CHECK-LABEL: fn foo(
@ -71,5 +70,4 @@ fn bar(bar: Bar) {
}
}
fn main() {}

View File

@ -35,7 +35,7 @@ fn if_let() {
_y = 42;
}
match _x { }
match _x {}
}
}
@ -56,7 +56,7 @@ fn as_match() {
// CHECK: return;
match empty() {
None => {}
Some(_x) => match _x {}
Some(_x) => match _x {},
}
}

View File

@ -3,7 +3,6 @@
// that we don't create filenames containing `<` and `>`
//@ compile-flags: -Zmir-opt-level=0
struct A;
// EMIT_MIR unusual_item_types.{impl#0}-ASSOCIATED_CONSTANT.built.after.mir
@ -23,8 +22,8 @@ enum E {
V = 5,
}
// EMIT_MIR core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
pub fn main() {
let f = Test::X as fn(usize) -> Test;
// EMIT_MIR core.ptr-drop_in_place.Vec_i32_.AddMovesForPackedDrops.before.mir
let v = Vec::<i32>::new();
}

Some files were not shown because too many files have changed in this diff Show More