Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling rustc with -Zrandomize-layout triggers assert in rustc_codegen_llvm/src/type_of.rs #101646

Closed
the8472 opened this issue Sep 10, 2022 · 3 comments
Labels
-Zrandomize-layout Unstable option: Randomize the layout of types. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@the8472
Copy link
Member

the8472 commented Sep 10, 2022

#101339 aims to enable -Zrandomize-layout in CI. Attempting to merge it results in this build failure.

It reproduces locally by checking out merge commit 7613125631f18e024b670e1764b3eeeca257045e and running ./src/ci/docker/run.sh x86_64-gnu-llvm-13.

With RUSTC_LOG=rustc_codegen_llvm::type_of=debug I get

DEBUG rustc_codegen_llvm::type_of struct_llfields: TyAndLayout {
    ty: debuginfo::metadata::type_map::UniqueTypeId,
    layout: Layout {
        size: Size(32 bytes),
        align: AbiAndPrefAlign {
            abi: Align(8 bytes),
            pref: Align(8 bytes),
        },
        abi: Aggregate {
            sized: true,
        },
        fields: Arbitrary {
            offsets: [
                Size(24 bytes),
                Size(16 bytes),
                Size(4 bytes),
            ],
            memory_index: [
                2,
                0,
                1,
            ],
        },
        largest_niche: None,
        variants: Single {
            index: 3,
        },
    },
}
DEBUG rustc_codegen_llvm::type_of struct_llfields: 1: TyAndLayout { ty: rustc_target::abi::VariantIdx, layout: Layout { size: Size(4 bytes), align: AbiAndPrefAlign { abi: Align(4 bytes), pref: Align(8 bytes) }, abi: Scalar(Initialized { value: Int(I32, false), valid_range: 0..=4294967040 }), fields: Arbitrary { offsets: [Size(0 bytes)], memory_index: [0] }, largest_niche: Some(Niche { offset: Size(0 bytes), value: Int(I32, false), valid_range: 0..=4294967040 }), variants: Single { index: 0 } } } offset: Size(0 bytes) target_offset: Size(16 bytes) effective_field_align: 4
DEBUG rustc_codegen_llvm::type_of     padding before: Size(16 bytes)
DEBUG rustc_codegen_llvm::type_of struct_llfields: 2: TyAndLayout { ty: debuginfo::metadata::type_map::private::HiddenZst, layout: Layout { size: Size(0 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), pref: Align(8 bytes) }, abi: Aggregate { sized: true }, fields: Arbitrary { offsets: [], memory_index: [] }, largest_niche: None, variants: Single { index: 0 } } } offset: Size(20 bytes) target_offset: Size(4 bytes) effective_field_align: 1
thread 'rustc' panicked at 'assertion failed: target_offset >= offset', compiler/rustc_codegen_llvm/src/type_of.rs:129:9
stack backtrace:
   0:     0x7f282b105efd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::heec03eb9b2106f99
   1:     0x7f282b16bf79 - core::fmt::write::hdc2190284bc6d0d4
   2:     0x7f282b0f6e41 - std::io::Write::write_fmt::h42741f15affd0ecb
   3:     0x7f282b108f0e - std::panicking::default_hook::{{closure}}::ha3e47422d6cfd2aa
   4:     0x7f282b108bd7 - std::panicking::default_hook::h06e3da70e0c4e264
   5:     0x7f282bafaa74 - rustc_driver[3636f0421e6d8c75]::DEFAULT_HOOK::{closure#0}::{closure#0}
   6:     0x7f282b1096b7 - std::panicking::rust_panic_with_hook::h332b5ce1ed540d19
   7:     0x7f282b1094aa - std::panicking::begin_panic_handler::{{closure}}::hf2b83e53a3e49fbf
   8:     0x7f282b106464 - std::sys_common::backtrace::__rust_end_short_backtrace::hc87a83fccecce6d2
   9:     0x7f282b1091a2 - rust_begin_unwind
  10:     0x7f282b0bcc23 - core::panicking::panic_fmt::h55dfedac6f6597d4
  11:     0x7f282b0bcaf3 - core::panicking::panic::h858d0a26258d295c
  12:     0x7f282bd37d83 - rustc_codegen_llvm[7b6a0d1032d5a3f0]::type_of::struct_llfields
  13:     0x7f282bd20b65 - <rustc_target[8d82747607a543bd]::abi::TyAndLayout<rustc_middle[10b8fe355026857d]::ty::Ty> as rustc_codegen_llvm[7b6a0d1032d5a3f0]::type_of::LayoutLlvmExt>::llvm_type
  14:     0x7f282bd258ba - <rustc_codegen_ssa[ace718b546837800]::mir::place::PlaceRef<&rustc_codegen_llvm[7b6a0d1032d5a3f0]::llvm_::ffi::Value>>::project_downcast::<rustc_codegen_llvm[7b6a0d1032d5a3f0]::builder::Builder>
  15:     0x7f282be56507 - <rustc_codegen_ssa[ace718b546837800]::mir::FunctionCx<rustc_codegen_llvm[7b6a0d1032d5a3f0]::builder::Builder>>::codegen_place
  16:     0x7f282be47b7d - <rustc_codegen_ssa[ace718b546837800]::mir::FunctionCx<rustc_codegen_llvm[7b6a0d1032d5a3f0]::builder::Builder>>::codegen_rvalue_operand
  17:     0x7f282be4e74a - <rustc_codegen_ssa[ace718b546837800]::mir::FunctionCx<rustc_codegen_llvm[7b6a0d1032d5a3f0]::builder::Builder>>::codegen_block
  18:     0x7f282be43446 - rustc_codegen_ssa[ace718b546837800]::mir::codegen_mir::<rustc_codegen_llvm[7b6a0d1032d5a3f0]::builder::Builder>
  19:     0x7f282bd57937 - rustc_codegen_ssa[ace718b546837800]::base::codegen_instance::<rustc_codegen_llvm[7b6a0d1032d5a3f0]::builder::Builder>

CC @Kixiron

@the8472 the8472 added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. labels Sep 10, 2022
@Kixiron
Copy link
Member

Kixiron commented Sep 12, 2022

I'm fairly sure I fixed this in #97861 but I haven't worked on that PR in a while

dtolnay added a commit to dtolnay/prettyplease that referenced this issue Feb 19, 2023
This reverts commit ef7636f.

rust-lang/rust#101646

    thread 'rustc' panicked at 'assertion failed: target_offset >= offset', compiler/rustc_codegen_llvm/src/type_of.rs:126:9
    stack backtrace:
       0:     0x7f5ec70a0a7a - std::backtrace_rs::backtrace::libunwind::trace::h9ab7cd28287cf18f
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
       1:     0x7f5ec70a0a7a - std::backtrace_rs::backtrace::trace_unsynchronized::h3e7e6ca06d1d63cf
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
       2:     0x7f5ec70a0a7a - std::sys_common::backtrace::_print_fmt::h5b6184fd459f0c71
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/sys_common/backtrace.rs:65:5
       3:     0x7f5ec70a0a7a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8ed5468732b78071
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/sys_common/backtrace.rs:44:22
       4:     0x7f5ec71009fe - core::fmt::write::h89c1e855e81d7a96
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/core/src/fmt/mod.rs:1232:17
       5:     0x7f5ec7090f25 - std::io::Write::write_fmt::ha23ba71db044374b
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/io/mod.rs:1684:15
       6:     0x7f5ec70a0845 - std::sys_common::backtrace::_print::h194cdf55c322d5fe
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/sys_common/backtrace.rs:47:5
       7:     0x7f5ec70a0845 - std::sys_common::backtrace::print::h4549e75783bab124
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/sys_common/backtrace.rs:34:9
       8:     0x7f5ec70a35bf - std::panicking::default_hook::{{closure}}::h04a46ea9ff60bf2c
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/panicking.rs:267:22
       9:     0x7f5ec70a32fb - std::panicking::default_hook::h6f3c116d48f73fba
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/panicking.rs:286:9
      10:     0x7f5eca3725f5 - <rustc_driver_impl[48a98004e06292cf]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[69c2f5c35675f1ee]::ops::function::FnOnce<(&core[69c2f5c35675f1ee]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
      11:     0x7f5ec70a3dfd - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h779d28c2deb011a8
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/alloc/src/boxed.rs:2002:9
      12:     0x7f5ec70a3dfd - std::panicking::rust_panic_with_hook::h5a936503487f19f5
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/panicking.rs:692:13
      13:     0x7f5ec70a3b32 - std::panicking::begin_panic_handler::{{closure}}::hf8db4efce7a7f23f
      31:     0x7f41b0ad0088 - <rustc_middle[2a277d44e6a99f4f]::ty::context::GlobalCtxt>::enter::<<rustc_interface[3e6023fe39c52850]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[69c2f5c35675f1ee]::result::Result<alloc[d821da156a43ed98]::boxed::Box<dyn core[69c2f5c35675f1ee]::any::Any>, rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>>
      32:     0x7f41b0acf774 - <rustc_interface[3e6023fe39c52850]::queries::Queries>::ongoing_codegen
      33:     0x7f41b0ace91a - <rustc_interface[3e6023fe39c52850]::interface::Compiler>::enter::<rustc_driver_impl[48a98004e06292cf]::run_compiler::{closure#1}::{closure#2}, core[69c2f5c35675f1ee]::result::Result<core[69c2f5c35675f1ee]::option::Option<rustc_interface[3e6023fe39c52850]::queries::Linker>, rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>>
      34:     0x7f41b0acc9c4 - rustc_span[97beb3ced854c2e2]::with_source_map::<core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>, rustc_interface[3e6023fe39c52850]::interface::run_compiler<core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>, rustc_driver_impl[48a98004e06292cf]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
      35:     0x7f41b0acbf2d - std[d6315e0f51da5517]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3e6023fe39c52850]::util::run_in_thread_pool_with_globals<rustc_interface[3e6023fe39c52850]::interface::run_compiler<core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>, rustc_driver_impl[48a98004e06292cf]::run_compiler::{closure#1}>::{closure#0}, core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>>
      36:     0x7f41b0acb97c - <<std[d6315e0f51da5517]::thread::Builder>::spawn_unchecked_<rustc_interface[3e6023fe39c52850]::util::run_in_thread_pool_with_globals<rustc_interface[3e6023fe39c52850]::interface::run_compiler<core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>, rustc_driver_impl[48a98004e06292cf]::run_compiler::{closure#1}>::{closure#0}, core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[69c2f5c35675f1ee]::result::Result<(), rustc_errors[abf5e0320c3520e7]::ErrorGuaranteed>>::{closure#1} as core[69c2f5c35675f1ee]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
      37:     0x7f41ae57fc83 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::heeffe32503a99aa5
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/alloc/src/boxed.rs:1988:9
      38:     0x7f41ae57fc83 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5085270dbf970bb4
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/alloc/src/boxed.rs:1988:9
      39:     0x7f41ae57fc83 - std::sys::unix::thread::Thread::new::thread_start::h76c3abd575e0d195
                                   at /rustc/4507fdaaa27ea2fb59a41df2ce7d1f290da53dae/library/std/src/sys/unix/thread.rs:108:17
      40:     0x7f41ae2c0b43 - <unknown>
      41:     0x7f41ae352a00 - <unknown>
      42:                0x0 - <unknown>

    error: the compiler unexpectedly panicked. this is a bug.

    note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

    note: rustc 1.69.0-nightly (4507fdaaa 2023-02-18) running on x86_64-unknown-linux-gnu

    note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -Z randomize-layout

    note: some of the compiler flags provided by cargo are hidden

    query stack during panic:
    end of query stack
    error: could not compile `prettyplease`
    Error: Process completed with exit code 101.
trevyn added a commit to trevyn/turbocharger that referenced this issue Jun 10, 2023
@Enselic Enselic added the -Zrandomize-layout Unstable option: Randomize the layout of types. label Apr 19, 2024
@WaffleLapkin
Copy link
Member

is this still happening?

@the8472
Copy link
Member Author

the8472 commented Aug 31, 2024

No longer seems to happen.

@the8472 the8472 closed this as completed Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zrandomize-layout Unstable option: Randomize the layout of types. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants