Skip to content

Broken MIR in encoding_rs related to MIR inlining + DestProp #105428

Closed

Description

@saethlin

This was originally #105344 (comment)


Trying to compile https://github.com/hsivonen/encoding_rs 5931e21bc20bad0335964f441da0c4309401107a with these flags:

$ RUSTFLAGS="-Zmir-opt-level=3 -Zvalidate-mir -Zinline-mir=yes" cargo +nightly test

Produces this:

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:1315 ~ encoding_rs[5e1f]::utf_16::{impl#0}::decode_to_utf16_raw), const_param_did: None }) (before pass SimplifyCfg-final) at bb218[0]:
                                encountered overlapping memory in `Call` terminator: _454 = bswap::<u16>(move _454) -> bb163
  --> src/utf_16.rs:85:21
   |
85 |                     dest.copy_utf16_from::<LittleEndian>(&mut source)
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:784:26

Removing -Zinline-mir=yes or -Zmir-opt-level=3 removes the ICE.


searched nightlies: from nightly-2022-01-01 to nightly-2022-12-05
regressed nightly: nightly-2022-11-28
searched commit range: 80a9646...1eb62b1
regressed commit: 0e9eee6

bisected with cargo-bisect-rustc v0.6.5

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --script script --start 2022-01-01 --end 2022-12-05 

Activity

  1. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Dec 8, 2022
  2. added a commit that references this issue on Dec 18, 2022
    f2f297a
  3. RalfJung commented on Jan 2, 2024

    @RalfJung
    Member

    @tmiasko I am trying to understand what happened here. The test case added in #105420 looks like maybe the analysis done by DestProp is smart enough to ignore dead code and that's why it can introduce UB in dead code?

    However the code at the top of this issue looks quite different. Looking at it's source, I can't see how ignoring dead code would lead to introducing overlapping calls?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions