rust/compiler
bors 550e035a59 Auto merge of #136450 - compiler-errors:simplify-cast, r=saethlin
Don't reset cast kind without also updating the operand in `simplify_cast` in GVN

Consider this heavily elided segment of the pre-GVN example code that was committed as a test:

```rust
          let _4: *const ();
          let _5: *const [()];
          let mut _6: *const ();
          let _7: *mut ();
          let mut _8: *const [()];
          let mut _9: std::boxed::Box<()>;
          let mut _10: *const ();
          /* ... */
          // Deref a box
          _10 = copy ((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>) as *const () (Transmute);
          _4 = copy _10;
          _6 = copy _4;
          // Inlined body of `slice::from_raw_parts`, to turn a unit pointer into a slice-of-unit pointer
          _5 = *const [()] from (copy _6, copy _11);
          _8 = copy _5;
          // Cast the raw slice-of-unit pointer back to a unit pointer
          _7 = copy _8 as *mut () (PtrToPtr);
```

A malformed optimization was changing `_7` (which casted the slice-of-unit ptr to a unit ptr) to:

```
          _7 = copy _5 as *mut () (Transmute);
```

...where `_8` was just replaced with `_5` bc of simple copy propagation, that part is not important... the CastKind changing to Transmute is the important part here.

In #133324, two new functionalities were implemented:
* Peeking through unsized -> sized PtrToPtr casts whose operand is `AggregateKind::RawPtr`, to turn it into PtrToPtr casts of the base of the aggregate. In this case, this allows us to see that the value of `_7` is just a ptr-to-ptr cast of `_6`.
* Folding a PtrToPtr cast of an operand which is a Transmute cast into just a single Transmute, which (theoretically) allows us to treat `_7` as a transmute into `*mut ()` of the base of the cast of `_10`, which is the place projection of `((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>)`.

However, when applying those two subsequent optimizations, we must *not* update the CastKind of the final cast *unless* we also update the operand of the cast, since the operand may no longer make sense with the updated CastKind.

In this case, this is problematic because the type of `_8` is `*const [()]`, but that operand in assignment statement of `_7` does *not* get turned into something like `((_9.0: std::ptr::Unique<()>).0: std::ptr::NonNull<()>)` -- **in other words, `try_to_operand` fails** -- because GVN only turns value nodes into locals or consts, not projections of locals. So we fail to update the operand, but we still update the CastKind to Transmute, which means we now are transmuting types of different sizes (a wide pointer and a thin pointer).

r? `@scottmcm` or `@cjgillot`

Fixes #136361
Fixes #135997
2025-02-07 06:26:41 +00:00
..
rustc
rustc_abi Auto merge of #135047 - Flakebi:amdgpu-kernel-cc, r=workingjubilee 2025-01-17 04:36:09 +00:00
rustc_arena Add inherent versions of MaybeUninit methods for slices 2025-01-11 23:57:00 -05:00
rustc_ast Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_ast_ir
rustc_ast_lowering Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_ast_passes Rename rustc_contract to contract 2025-02-03 13:55:15 -08:00
rustc_ast_pretty Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_attr_data_structures rustc_allowed_through_unstable_modules: require deprecation message 2025-02-02 12:36:12 +01:00
rustc_attr_parsing rustc_allowed_through_unstable_modules: require deprecation message 2025-02-02 12:36:12 +01:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obk 2025-02-05 05:03:01 +01:00
rustc_builtin_macros Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_codegen_cranelift Rollup merge of #136537 - tgross35:update-builtins, r=tgross35 2025-02-05 19:09:37 +08:00
rustc_codegen_gcc Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_codegen_llvm Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_codegen_ssa Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_const_eval Rollup merge of #136235 - oli-obk:transmuty-pat-tys, r=RalfJung 2025-02-06 13:09:58 +01:00
rustc_data_structures Rollup merge of #136580 - bjorn3:miri_fixes, r=lqd 2025-02-06 21:56:27 +01:00
rustc_driver
rustc_driver_impl Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors 2025-02-06 21:56:28 +01:00
rustc_error_codes Auto merge of #133154 - estebank:issue-133137, r=wesleywiser 2025-01-25 11:41:21 +00:00
rustc_error_messages tree-wide: parallel: Fully removed all Lrc, replaced with Arc 2025-02-03 13:25:57 +03:00
rustc_errors Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors 2025-02-06 21:56:28 +01:00
rustc_expand tree-wide: parallel: Fully removed all Lrc, replaced with Arc 2025-02-03 13:25:57 +03:00
rustc_feature Rollup merge of #128045 - pnkfelix:rustc-contracts, r=oli-obk 2025-02-05 05:03:01 +01:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir Rollup merge of #136219 - yotamofek:pr/hir-cleanup, r=compiler-errors 2025-02-06 21:56:26 +01:00
rustc_hir_analysis Rollup merge of #136073 - compiler-errors:recursive-coro-always, r=oli-obk 2025-02-06 13:09:57 +01:00
rustc_hir_pretty Add rustc_hir_pretty::expr_to_string function 2025-02-05 18:25:33 +01:00
rustc_hir_typeck Rollup merge of #136315 - estebank:long-ty-binop, r=SparrowLii 2025-02-06 13:09:59 +01:00
rustc_incremental Remove hook calling via TyCtxtAt. 2025-02-03 17:02:33 +11:00
rustc_index Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
rustc_index_macros
rustc_infer Pass spans around new solver 2025-02-05 18:32:06 +00:00
rustc_interface Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors 2025-02-06 21:56:28 +01:00
rustc_lexer implement eat_until leveraging memchr in lexer 2025-02-05 07:03:53 -08:00
rustc_lint Rollup merge of #136393 - oli-obk:pattern-type-lit-oflo-checks, r=compiler-errors 2025-02-06 13:09:59 +01:00
rustc_lint_defs Rollup merge of #135964 - ehuss:cenum_impl_drop_cast, r=Nadrieril 2025-02-05 19:09:33 +08:00
rustc_llvm Use LLVMDIBuilderCreateDebugLocation 2025-02-01 14:14:40 +11:00
rustc_log
rustc_macros Rename ensure_forwards_result_if_red to return_result_from_ensure_ok 2025-02-01 12:42:41 +11:00
rustc_metadata Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_middle Auto merge of #136641 - matthiaskrgr:rollup-lajwje5, r=matthiaskrgr 2025-02-06 17:08:45 +00:00
rustc_mir_build Rollup merge of #136435 - Zalathar:thir-pat-stuff, r=Nadrieril 2025-02-06 13:10:00 +01:00
rustc_mir_dataflow Contracts core intrinsics. 2025-02-03 12:53:57 -08:00
rustc_mir_transform Don't reset cast kind without also updating the operand in simplify_cast 2025-02-06 18:39:35 +00:00
rustc_monomorphize Auto merge of #136481 - jieyouxu:rollup-w0lnnqb, r=jieyouxu 2025-02-03 16:42:25 +00:00
rustc_next_trait_solver Rollup merge of #136069 - yotamofek:next-solver-slice, r=compiler-errors 2025-02-06 21:56:25 +01:00
rustc_parse Stop passing the same resource multiple times when building ParseSess 2025-02-06 17:30:10 +00:00
rustc_parse_format use impl Into<String> 2025-01-29 09:48:08 +01:00
rustc_passes Rollup merge of #133925 - folkertdev:improve-repr-warnings, r=compiler-errors 2025-02-06 21:56:24 +01:00
rustc_pattern_analysis Get rid of mir::Const::from_ty_const 2025-01-20 04:26:44 +00:00
rustc_privacy Make comma separated lists of anything easier to make for errors 2025-01-31 20:36:44 +00:00
rustc_query_impl Remove hook calling via TyCtxtAt. 2025-02-03 17:02:33 +11:00
rustc_query_system Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_resolve Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_sanitizers check the types in ty::Value to value conversion 2025-01-30 18:13:16 +01:00
rustc_serialize
rustc_session Rollup merge of #136636 - bjorn3:error_cleanup, r=compiler-errors 2025-02-06 21:56:28 +01:00
rustc_smir Implement RustcInternal for RawPtrKind 2025-02-05 11:32:19 -05:00
rustc_span Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_symbol_mangling Move try_to_raw_bytes from ty::Valtree to ty::Value 2025-02-03 18:33:27 +01:00
rustc_target Rollup merge of #133932 - bjorn3:fix_ptx_kernel_abi, r=wesleywiser 2025-02-05 19:53:45 -08:00
rustc_trait_selection Rollup merge of #136311 - compiler-errors:vtable-fixes-2, r=lcnr 2025-02-06 13:09:58 +01:00
rustc_traits Auto merge of #136011 - compiler-errors:query-norm-vaniquishes-us, r=jackh726 2025-01-29 02:12:12 +00:00
rustc_transmute introduce ty::Value 2025-01-30 17:47:44 +01:00
rustc_ty_utils Rollup merge of #136435 - Zalathar:thir-pat-stuff, r=Nadrieril 2025-02-06 13:10:00 +01:00
rustc_type_ir Auto merge of #136471 - safinaskar:parallel, r=SparrowLii 2025-02-06 10:50:05 +00:00
rustc_type_ir_macros
stable_mir Contracts core intrinsics. 2025-02-03 12:53:57 -08:00