Skip to content

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

Description

@the8472

#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

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Sep 10, 2022
  2. Kixiron commented on Sep 12, 2022

    @Kixiron
    Contributor

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

  3. WaffleLapkin commented on Aug 27, 2024

    @WaffleLapkin
    Member

    is this still happening?

  4. the8472 commented on Aug 31, 2024

    @the8472
    MemberAuthor

    No longer seems to happen.

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

    -Zrandomize-layoutUnstable option: Randomize the layout of types.C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.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