Commit Graph

100 Commits

Author SHA1 Message Date
George Bateman 23f46e5b99 Stabilize offset_of_nested 2024-07-29 17:50:12 +01:00
DianQK ae681c940d Perform instsimplify before inline to eliminate some trivial calls 2024-07-29 18:14:35 +08:00
Ulrich Weigand 636ddcb099 Ignore allocation bytes in one more mir-opt test
Following on PR #126502, add `rustc -Zdump-mir-exclude-alloc-bytes`
to tests/mir-opt/dataflow-const-prop/aggregate_copy.rs as well
to skip writing allocation bytes in MIR dumps.

Fixes #126261
2024-07-15 10:18:06 +02:00
Camille GILLOT 7ac7f135e3 Propagate places through assignments. 2024-07-13 12:02:10 +00:00
Camille GILLOT af876626b0 Add test for copying aggregates. 2024-07-13 11:54:30 +00:00
Camille GILLOT 76f5bc6a9f Create mapped places upon seeing them in the body. 2024-07-13 11:54:25 +00:00
Josh Stone 7c3673ff6f Bless mir-opt for excluded alloc bytes 2024-06-26 15:30:47 -07:00
Josh Stone 1a05cb2d93 Use -Zdump-mir-exclude-alloc-bytes in some mir-opt tests 2024-06-26 15:05:01 -07:00
Scott McMurray 4630d1b23b Ban ArrayToPointer and MutToConstPointer from runtime MIR
Apparently MIR borrowck cares about at least one of these for checking variance.

In runtime MIR, though, there's no need for them as `PtrToPtr` does the same thing.

(Banning them simplifies passes like GVN that no longer need to handle multiple cast possibilities.)
2024-06-19 10:44:01 -07:00
Nicholas Nethercote c9c80d2c5f rustfmt tests/mir-opt.
The only non-obvious changes:
- `building/storage_live_dead_in_statics.rs` has a `#[rustfmt::skip]`
  attribute to avoid reformating a table of data.
- Two `.mir` files have slight changes involving line numbers.
- In `unusual_item_types.rs` an `EMIT_MIR` annotation is moved to
  outside a function, which is the usual spot, because `tidy` complains
  if such a comment is indented.

The commit also tweaks the comments in `rustfmt.toml`.
2024-06-03 14:17:16 +10:00
Nicholas Nethercote ac24299636 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()
      }
  }
  ```
2024-06-03 13:24:44 +10:00
Scott McMurray 95c0e5c6a8 Remove Rvalue::CheckedBinaryOp 2024-05-17 20:33:02 -07:00
George Bateman 2348eb271c Update mir-opt tests, add proper regression test 2024-04-28 21:10:09 +01:00
Ralf Jung 75d0fdd967 mir-opt tests: rename unit-test -> test-mir-pass 2024-04-20 13:19:34 +02:00
Scott McMurray d05545c05d At debuginfo=0, don't inline debuginfo when inlining 2024-04-18 09:35:35 -07:00
Matthew Jasper a277c901d9 Remove MIR unsafe check
This also remove safety information from MIR.
2024-04-03 08:50:12 +00:00
bors 2f090c30dd Auto merge of #122629 - RalfJung:assert-unsafe-precondition, r=saethlin
refactor check_{lang,library}_ub: use a single intrinsic

This enacts the plan I laid out [here](https://github.com/rust-lang/rust/pull/122282#issuecomment-1996917998): use a single intrinsic, called `ub_checks` (in aniticpation of https://github.com/rust-lang/compiler-team/issues/725), that just exposes the value of `debug_assertions` (consistently implemented in both codegen and the interpreter). Put the language vs library UB logic into the library.

This makes it easier to do something like https://github.com/rust-lang/rust/pull/122282 in the future: that just slightly alters the semantics of `ub_checks` (making it more approximating when crates built with different flags are mixed), but it no longer affects whether these checks can happen in Miri or compile-time.

The first commit just moves things around; I don't think these macros and functions belong into `intrinsics.rs` as they are not intrinsics.

r? `@saethlin`
2024-03-23 21:11:00 +00:00
Ralf Jung 6177530420 refactor check_{lang,library}_ub: use a single intrinsic, put policy into library 2024-03-23 18:45:05 +01:00
Ben Kimock 07994c9310 Enable more mir-opt tests in debug builds 2024-03-22 20:14:39 -04:00
Ralf Jung 7d99e80c55 MIR printing: print the path of uneval'd const; refer to promoteds in a consistent way 2024-03-10 14:59:41 +01:00
Ben Kimock 5a93a59fd5 Distinguish between library and lang UB in assert_unsafe_precondition 2024-03-08 18:53:58 -05:00
许杰友 Jieyou Xu (Joe) 6e48b96692 [AUTO_GENERATED] Migrate compiletest to use ui_test-style //@ directives 2024-02-22 16:04:04 +00:00
Ralf Jung b58f647d54 rename ptr::invalid -> ptr::without_provenance
also introduce ptr::dangling matching NonNull::dangling
2024-02-21 20:15:52 +01:00
Oli Scherer 9062697917 Always evaluate free constants and statics, even if previous errors occurred 2024-02-19 22:11:13 +00:00
Matthias Krüger b785fdb80b Rollup merge of #120978 - Nadrieril:sane-blocks, r=matthewjasper
match lowering: simplify block creation

Match lowering was doing complicated things with block creation. As far as I can tell it was trying to avoid creating unneeded blocks, but of the three places that start out with `otherwise = &mut None`, two of them called `otherwise.unwrap_or_else(|| self.cfg.start_new_block())` anyway. As far as I can tell the only place where this PR makes a difference is in `lower_match_tree`, which did indeed sometimes avoid creating the unreachable final block + FakeRead. Unless this is important I propose we do the naive thing instead.

I have not checked all the graph isomorphisms by hand, but at a glance the test diff looks sensible.

r? `@matthewjasper`
2024-02-13 17:38:11 +01:00
Nadrieril faaf81bbbc Start blocks eagerly 2024-02-12 17:37:05 +01:00
Camille GILLOT d50f26e409 Const-prop pointers. 2024-02-09 21:06:23 +00:00
Ben Kimock 611c3cb561 Bless/fix tests 2024-02-08 19:56:30 -05:00
Matthias Krüger 2b259577aa Rollup merge of #119759 - sfzhu93:master, r=cjgillot
Add FileCheck annotations to dataflow-const-prop tests

part of #116971.

A few shadowing variable names are changed, so that it is easier to match the variable names in MIR using FileCheck syntax.

Also, there's a FIXME in [enum.rs](https://github.com/rust-lang/rust/pull/119759/files#diff-7621f55327838e489a95ac99ae1e6126b37c57aff582594e6bee9d7e7e56fc58) because the MIR looks suspicious to me. It has been explained in the comments.

r? cjgillot
2024-02-04 19:42:09 +01:00
sfzhu93 699b59c01d update terminator.rs 2024-01-28 22:44:32 -08:00
sfzhu93 65b10839d6 update enum.rs 2024-01-22 17:34:49 -08:00
sfzhu93 7ad307dc9d finish a pattern in enum.rs 2024-01-20 08:22:07 -08:00
sfzhu93 edba94907d update misuse of check-label 2024-01-20 08:09:14 -08:00
George Bateman 803b810eac Remove feature(offset_of) from tests 2024-01-19 20:38:51 +00:00
sfzhu93 5747eceef8 add FIXME for default_boxed_slice.rs 2024-01-14 22:35:00 -08:00
sfzhu93 cd77d59f97 update enum.rs for code review 2024-01-12 20:50:28 -08:00
sfzhu93 1c886d794c resolve code reviews 2024-01-11 23:36:09 -08:00
sfzhu93 d63f10b7ad resolve code reviews 2024-01-11 23:22:33 -08:00
Camille GILLOT 0aedd6e86f Sandwich MIR optimizations between DSE. 2024-01-11 09:58:19 +00:00
sfzhu93 7135168d08 Add FileCheck for enum.rs 2024-01-08 21:58:01 -08:00
sfzhu93 1adda9a170 Add FileCheck to terminator.rs and tuple.rs 2024-01-08 20:21:23 -08:00
sfzhu93 732f6a1303 Add FileCheck to struct.rs 2024-01-08 20:21:06 -08:00
sfzhu93 d765e3ae1f Add FileCheck to slice_len.rs 2024-01-08 20:20:53 -08:00
sfzhu93 3ab1d5d450 Add FileCheck to 3 tests: self_assign_add, self_assign, and sibling_ptr 2024-01-08 20:20:27 -08:00
sfzhu93 e9152e2b6c Add FileCheck to 3 tests: ref_without_sb, repeat, repr_transparent 2024-01-08 20:19:59 -08:00
sfzhu93 9452d7ed1a Add FileCheck to 3 tests: large_array_index, mult_by_zero, and offset_of 2024-01-08 20:18:59 -08:00
sfzhu93 24aefa0e5d Add FileCheck for if.rs, inherit_overflow.rs, issue_81605.rs 2024-01-08 17:01:13 -08:00
sfzhu93 33e5d851a9 Add FileCheck for enum.rs 2024-01-07 22:03:42 -08:00
sfzhu93 e05c779ee3 Add FileCheck for checked.rs and default_boxed_slice.rs. 2024-01-07 21:16:55 -08:00
sfzhu93 1eaeaaf08b Add FileCheck for array_index.rs, boolean_identities.rs and cast.rs 2024-01-07 21:16:22 -08:00