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

Added randomized field padding to -Z randomize-layout #97861

Closed
wants to merge 2 commits into from

Conversation

Kixiron
Copy link
Member

@Kixiron Kixiron commented Jun 8, 2022

Adds randomized padding before each struct field in valid structs when -Z randomize-layout is enabled, the maximum amount of padding is decided by the -Z max-layout-multiple=<MULTIPLE> flag.
This allows easier and more reliable detection of layout-based UB by greatly increasing the possibility of different structs having massively different layouts due to their sizes, field offsets, etc. being so different.
This actually introduces one small change in behavior vs. the past -Z randomize-layout, now repr(transparent) structs are never considered for layout randomization

cc @eddyb @saethlin

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 8, 2022
@rust-highfive
Copy link
Collaborator

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 8, 2022
@Kixiron Kixiron changed the title Added randomized field padding to -Z randomize-layout Added randomized field padding to -Z randomize-layout Jun 8, 2022
@saethlin
Copy link
Member

saethlin commented Jun 8, 2022

This ICEs when I run RUSTFLAGS_NOT_BOOTSTRAP=-Zrandomize-layout x test.

ICE output
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling cc v1.0.69
   Compiling core v0.0.0 (/home/ben/rust/library/core)
   Compiling libc v0.2.126
   Compiling memchr v2.4.1
   Compiling std v0.0.0 (/home/ben/rust/library/std)
   Compiling compiler_builtins v0.1.73
   Compiling unwind v0.0.0 (/home/ben/rust/library/unwind)
   Compiling rustc-std-workspace-core v1.99.0 (/home/ben/rust/library/rustc-std-workspace-core)
error: internal compiler error: compiler/rustc_lint/src/types.rs:796:13: improper_ctypes: Option nonnull optimization not applied?

thread 'rustc' panicked at 'Box<dyn Any>', /home/ben/rust/compiler/rustc_errors/src/lib.rs:1334:9
stack backtrace:
   0:     0x7f70b8f1b8fd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he38c7361b94c5d0c
   1:     0x7f70b8f6443e - core::fmt::write::h1a02af67ba355677
   2:     0x7f70b8ed3081 - std::io::Write::write_fmt::h453053024c73966b
   3:     0x7f70b8ee7e55 - std::panicking::default_hook::{{closure}}::hfdf6d0b1b3859d98
   4:     0x7f70b8ee7ab7 - std::panicking::default_hook::h14232858b308420c
   5:     0x7f70b969d3e6 - rustc_driver[bbe82ef0d8e75ea1]::DEFAULT_HOOK::{closure#0}::{closure#0}
   6:     0x7f70b8ee8634 - std::panicking::rust_panic_with_hook::h5215b735b1ea29b6
   7:     0x7f70bbce39f3 - std[a689b2ed93f5df76]::panicking::begin_panic::<rustc_errors[2825527422c22d3]::ExplicitBug>::{closure#0}
   8:     0x7f70bbce15a6 - std[a689b2ed93f5df76]::sys_common::backtrace::__rust_end_short_backtrace::<std[a689b2ed93f5df76]::panicking::begin_panic<rustc_errors[2825527422c22d3]::ExplicitBug>::{closure#0}, !>
   9:     0x7f70b95db396 - std[a689b2ed93f5df76]::panicking::begin_panic::<rustc_errors[2825527422c22d3]::ExplicitBug>
  10:     0x7f70bbb17c26 - std[a689b2ed93f5df76]::panic::panic_any::<rustc_errors[2825527422c22d3]::ExplicitBug>
  11:     0x7f70bbb166e0 - <rustc_errors[2825527422c22d3]::HandlerInner>::bug::<&alloc[9dfe1f9b2c9bdb6]::string::String>
  12:     0x7f70bbb16330 - <rustc_errors[2825527422c22d3]::Handler>::bug::<&alloc[9dfe1f9b2c9bdb6]::string::String>
  13:     0x7f70bbcf2e5a - rustc_middle[8693c79d52a1849d]::ty::context::tls::with_opt::<rustc_middle[8693c79d52a1849d]::util::bug::opt_span_bug_fmt<rustc_span[9e269396fce057fe]::span_encoding::Span>::{closure#0}, ()>
  14:     0x7f70bbcf2ec9 - rustc_middle[8693c79d52a1849d]::util::bug::opt_span_bug_fmt::<rustc_span[9e269396fce057fe]::span_encoding::Span>
  15:     0x7f70b95e1305 - rustc_middle[8693c79d52a1849d]::util::bug::bug_fmt
  16:     0x7f70bb7e90ed - rustc_lint[90eccce51c55190]::types::repr_nullable_ptr
  17:     0x7f70bb7e9fd8 - <rustc_lint[90eccce51c55190]::types::ImproperCTypesVisitor>::check_type_for_ffi
  18:     0x7f70bb7ea768 - <rustc_lint[90eccce51c55190]::types::ImproperCTypesVisitor>::check_type_for_ffi_and_report_errors
  19:     0x7f70bb7eb158 - <rustc_lint[90eccce51c55190]::types::ImproperCTypesVisitor>::check_foreign_fn
  20:     0x7f70bb7fb39d - <rustc_lint[90eccce51c55190]::late::LateContextAndPass<rustc_lint[90eccce51c55190]::BuiltinCombinedModuleLateLintPass> as rustc_hir[4282039d40c377b4]::intravisit::Visitor>::visit_fn
  21:     0x7f70bb854399 - rustc_hir[4282039d40c377b4]::intravisit::walk_item::<rustc_lint[90eccce51c55190]::late::LateContextAndPass<rustc_lint[90eccce51c55190]::BuiltinCombinedModuleLateLintPass>>
  22:     0x7f70bb7f9293 - <rustc_lint[90eccce51c55190]::late::LateContextAndPass<rustc_lint[90eccce51c55190]::BuiltinCombinedModuleLateLintPass> as rustc_hir[4282039d40c377b4]::intravisit::Visitor>::visit_nested_item
  23:     0x7f70bb7fc92d - rustc_lint[90eccce51c55190]::late::late_lint_mod::<rustc_lint[90eccce51c55190]::BuiltinCombinedModuleLateLintPass>
  24:     0x7f70bae29e2b - rustc_query_system[1523598a8d60b49]::query::plumbing::try_execute_query::<rustc_query_impl[320f40d31780e620]::plumbing::QueryCtxt, rustc_query_system[1523598a8d60b49]::query::caches::DefaultCache<rustc_span[9e269396fce057fe]::def_id::LocalDefId, ()>>
  25:     0x7f70baf1a635 - rustc_query_system[1523598a8d60b49]::query::plumbing::get_query::<rustc_query_impl[320f40d31780e620]::queries::lint_mod, rustc_query_impl[320f40d31780e620]::plumbing::QueryCtxt>
  26:     0x7f70b975b0ff - <rustc_middle[8693c79d52a1849d]::hir::map::Map>::for_each_module::<rustc_lint[90eccce51c55190]::late::check_crate<rustc_lint[90eccce51c55190]::BuiltinCombinedLateLintPass, rustc_interface[fa71196b0e93bb1c]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>
  27:     0x7f70b97f0a00 - <rustc_session[915c3399c980dc57]::session::Session>::time::<(), rustc_lint[90eccce51c55190]::late::check_crate<rustc_lint[90eccce51c55190]::BuiltinCombinedLateLintPass, rustc_interface[fa71196b0e93bb1c]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}>
  28:     0x7f70b97f0bf7 - <rustc_session[915c3399c980dc57]::session::Session>::time::<(), rustc_interface[fa71196b0e93bb1c]::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
  29:     0x7f70b97ac004 - <core[4c4fb2cd17933ed9]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[fa71196b0e93bb1c]::passes::analysis::{closure#5}::{closure#1}> as core[4c4fb2cd17933ed9]::ops::function::FnOnce<()>>::call_once
  30:     0x7f70b97f34de - <rustc_session[915c3399c980dc57]::session::Session>::time::<(), rustc_interface[fa71196b0e93bb1c]::passes::analysis::{closure#5}>
  31:     0x7f70b97e601c - rustc_interface[fa71196b0e93bb1c]::passes::analysis
  32:     0x7f70bae7bd09 - rustc_query_system[1523598a8d60b49]::query::plumbing::try_execute_query::<rustc_query_impl[320f40d31780e620]::plumbing::QueryCtxt, rustc_query_system[1523598a8d60b49]::query::caches::DefaultCache<(), core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>>
  33:     0x7f70baf1a127 - rustc_query_system[1523598a8d60b49]::query::plumbing::get_query::<rustc_query_impl[320f40d31780e620]::queries::analysis, rustc_query_impl[320f40d31780e620]::plumbing::QueryCtxt>
  34:     0x7f70b964f05b - <rustc_interface[fa71196b0e93bb1c]::passes::QueryContext>::enter::<rustc_driver[bbe82ef0d8e75ea1]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>
  35:     0x7f70b962d4b6 - <rustc_interface[fa71196b0e93bb1c]::interface::Compiler>::enter::<rustc_driver[bbe82ef0d8e75ea1]::run_compiler::{closure#1}::{closure#2}, core[4c4fb2cd17933ed9]::result::Result<core[4c4fb2cd17933ed9]::option::Option<rustc_interface[fa71196b0e93bb1c]::queries::Linker>, rustc_errors[2825527422c22d3]::ErrorGuaranteed>>
  36:     0x7f70b969eef3 - rustc_span[9e269396fce057fe]::with_source_map::<core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>, rustc_interface[fa71196b0e93bb1c]::interface::create_compiler_and_run<core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>, rustc_driver[bbe82ef0d8e75ea1]::run_compiler::{closure#1}>::{closure#1}>
  37:     0x7f70b962e27a - <scoped_tls[b383e8bf08376368]::ScopedKey<rustc_span[9e269396fce057fe]::SessionGlobals>>::set::<rustc_interface[fa71196b0e93bb1c]::interface::run_compiler<core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>, rustc_driver[bbe82ef0d8e75ea1]::run_compiler::{closure#1}>::{closure#0}, core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>
  38:     0x7f70b968849f - std[a689b2ed93f5df76]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fa71196b0e93bb1c]::util::run_in_thread_pool_with_globals<rustc_interface[fa71196b0e93bb1c]::interface::run_compiler<core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>, rustc_driver[bbe82ef0d8e75ea1]::run_compiler::{closure#1}>::{closure#0}, core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>::{closure#0}, core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>
  39:     0x7f70b9652a19 - <<std[a689b2ed93f5df76]::thread::Builder>::spawn_unchecked_<rustc_interface[fa71196b0e93bb1c]::util::run_in_thread_pool_with_globals<rustc_interface[fa71196b0e93bb1c]::interface::run_compiler<core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>, rustc_driver[bbe82ef0d8e75ea1]::run_compiler::{closure#1}>::{closure#0}, core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>::{closure#0}, core[4c4fb2cd17933ed9]::result::Result<(), rustc_errors[2825527422c22d3]::ErrorGuaranteed>>::{closure#1} as core[4c4fb2cd17933ed9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x7f70b8ef87a3 - std::sys::unix::thread::Thread::new::thread_start::hed61a4e9d6dc74b3
  41:     0x7f70b8c8c54d - <unknown>
  42:     0x7f70b8d11874 - clone
  43:                0x0 - <unknown>

note: 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.63.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C codegen-units=10000 -C debuginfo=0 -Z unstable-options -Z randomize-layout -C symbol-mangling-version=legacy -Z unstable-options -Z unstable-options -Z macro-backtrace -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -Z unstable-options -C split-debuginfo=off -C prefer-dynamic -C embed-bitcode=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -C panic=abort -Z force-unstable-if-unmarked

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

query stack during panic:
#0 [lint_mod] linting module `int::udiv`
#1 [analysis] running analysis passes on this crate
end of query stack

@Kixiron
Copy link
Member Author

Kixiron commented Jun 8, 2022

Did you run x clean first? This interacts really poorly with any previous artifacts since it makes deep codegen changes

@saethlin
Copy link
Member

saethlin commented Jun 8, 2022

Still get the same ICE with an x clean or rm -r build.

.unwrap_or(0)
} else {
0
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may not be any extra padding for option like types wrapping a type with a guaranteed niche.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're correct, I just don't know how to make that check

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've sworn there was an attribute on Option to indicate it was FFI-friendly (effectively guaranteeing its optimization), but right now it just has #[rustc_diagnostic_item]:

/// The `Option` type. See [the module level documentation](self) for more.
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
#[rustc_diagnostic_item = "Option"]
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Option<T> {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has #[rustc_nonnull_optimization_guaranteed], that may help

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, NonNull does, not Option, hah.

Welp, that's sneaky. Maybe you could pull out the code from SizeSkeleton::compute (or the FFI lint?), to detect Option-like enums, and make it check #[rustc_nonnull_optimization_guaranteed] for a custom type as the only non-ZST field... but I'm not 100% happy with that, I guess we've enshrined Option-like enums more than we should have?

At least such a hack could move things along.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it'd break anything to just slap #[rustc_nonnull_optimization_guaranteed] on Option? Or is it possible to check for the Some lang item while calculating the layout for it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make the ffi safety lint think that Option<Option<&T>> is ffi safe. You should probably copy the logic of repr_nullable_ptr in compiler/rustc_lint/src/types.rs instead. This is what the ffi safety lint uses.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning is different. #[rustc_nonnull_optimization_guaranteed] struct Foo implies that Option<Foo>, Result<Foo, ()> etc. are all the same size as Foo (well, assuming the niche actually exists, don't think the attribute actually checks for it).

We don't have another attribute for the enum and IIRC the FFI lint allows anything vaguely Option-shaped anyway, so you could mimic that.

If we want attributes on both NonNull and Option, we should find better name for them, as "nonnull payload" and "nullable optimization enum" (not saying that should be in the attribute name, just my first thought about the distinction between the two sides).

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 12, 2022
Comment on lines 1444 to 1445
max_layout_multiple: Option<u64> = (None, parse_opt_number, [TRACKED],
"set the maximum layout padding multiple when using 'randomize-layout' (default: 3)"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think -Z max-layout-multiple is clear enough that it's only about alignment padding, not the whole size. I don't have good suggestions but -Z layout-random-padding-max-factor is one of the shortest I can think of, that is self-explanatory to some extent.

@eddyb
Copy link
Member

eddyb commented Jun 13, 2022

cc @rust-lang/compiler @rust-lang/miri

I'd like more eyes on this -Z randomize-layout saga - especially more coordination towards a crater run would be great, as this holds exciting discovery potential for at least some forms of unsafe code incorrectness.

(but mainly I want to avoid this feature being mainly discussed privately, with most users largely unaware that they have this tool at their disposal, like what happened with semverver)

@Kixiron
Copy link
Member Author

Kixiron commented Jun 13, 2022

I believe that @saethlin has already been doing crater-style experiments with -Z randomize-layout and has even found some bugs with it

@saethlin
Copy link
Member

saethlin commented Jun 13, 2022

Heh, saw your comment appear while I'm trying to choose my words here.

FWIW I've done some study with the previous -Zrandomize-layout and I'm aware of a few crates that have such layout dependencies, though they seem blessedly sparse in the ecosystem. Most of them seem to know that what they're doing is inadvisable, so it's unclear to me what should be done. I strongly suspect that simply telling authors "you can't rely on this" is just telling them something they already know. For example:

https://github.com/phsym/prettytable-rs/blob/cf7dca33e2e2131c20e4bbc34ad222c5e6edc29a/src/lib.rs#L514-L517
https://github.com/watchexec/clearscreen/blob/c6590c902aeba137c806e5c5025c28339f0570c7/src/lib.rs#L1216-L1218

It would definitely be good to have an accurate survey of the use of this, but it's unclear to me how actionable that would be.

A crater run with -Zbuild-std + -Zrandomize-layout with the padding, if that disrupts the layout of single-field repr(Rust) structs would be much more exciting. I know a few crates copy-pasted code from the standard library that transmutes a std::sync::Weak<T> into a usize, and that code still behaves as expected with -Zbuild-std + -Zrandomize-layout which is available on nightly. I suspect such transmutes of wrappers are more common than structs with more than one field.


If such a crater run is done it should go from nightly + -Zbuild-std to nightly + -Zbuild-std + -Zrandomize-layout. Just -Zbuild-std on its own causes quite a few crates to SIGILL due to UB caught by debug assertions in the standard library, which are compiled out by default.

@RalfJung
Copy link
Member

I can't really help review this, but would be happy to see this feature advertised in the Miri README.

///
/// Currently supports function pointers (`fn(...) -> ..`), `Box<_>`, references, `NonNull<_>`,
/// `NonZero*` and `#[repr(transparent)]` newtypes around them
pub fn nonnull_opt_applies<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, is_definition: bool) -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somehow slightly incorrect, it looks like previously a true result was being treated as a "maybe" instead of a canonical "yes, this is can be null pointer opt'ed"
Specifically, it fails in std/src/io/error/repr_bitpacked.rs on a size assertion that Option<Repr> is 8 bytes where Repr is

#[repr(transparent)]
struct Repr(NonNull<()>, PhantomData<ErrorData<Box<Custom>>>);

Which confuses me since it should work?

  • nonnull_opt_applies() gets an Option<Repr> and sees that Option is Option-shaped
  • It gets the inner type, Repr
  • It passes Repr to ty_is_known_nonnull()
    • ty_is_known_nonnull() sees that Repr is a #[transparent] ADT which is not a union
    • Repr doesn't have #[rustc_nonnull_optimization_guaranteed] but that's ok, we continue
    • Repr doesn't have repr(no_niche) but that's ok, we continue
    • We find the non-zst field of Repr which is NonNull<()>
      • We call ty_is_known_nonnull() on NonNull<()>
      • NonNull<()> is a transparent ADT which isn't a union
      • NonNull<()> has #[nonnull_optimization_guaranteed], we return true
    • .any(|field| ty_is_known_nonnull(field)) gets a true from NonNull<()> and returns true
  • ty_is_known_nonnull(Repr) returns true

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it seems I forgot a ! when calling it

@Kixiron
Copy link
Member Author

Kixiron commented Jun 13, 2022

So I think I've gotten it working properly, however it ices when compiling alloc. I'm not sure if this is a "my code is buggy" ice or a "alloc is doing something weird with unspecified layouts" ice so if someone who's better at reading the fairly indecipherable backtraces could take a look that'd be great

Backtrace
 λ  x test
Updating only changed submodules
  Submodules updated in 0.12 seconds
Building rustbuild
   Compiling bootstrap v0.0.0 (G:\Users\Chase\Code\Rust\rust\src\bootstrap)
    Finished dev [unoptimized] target(s) in 8.72s
Building stage0 tool tidy (x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.36s
tidy check
* 630 error codes
* highest error code: E0788
Checking which error codes lack tests...
* 378 features
Found 505 error codes
Found 0 error(s) in error codes
Done!
fmt check
Building stage0 std artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.39s
Copying stage0 std from stage0 (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc / x86_64-pc-windows-msvc)
Building stage0 compiler artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
   Compiling rustc_llvm v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_llvm)
   Compiling rustc_middle v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_middle)
   Compiling rustc_infer v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_infer)
   Compiling rustc_metadata v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_metadata)
   Compiling rustc_mir_dataflow v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_mir_dataflow)
   Compiling rustc_symbol_mangling v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_symbol_mangling)
   Compiling rustc_incremental v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_incremental)
   Compiling rustc_query_impl v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_query_impl)
   Compiling rustc_monomorphize v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_monomorphize)
   Compiling rustc_passes v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_passes)
   Compiling rustc_save_analysis v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_save_analysis)
   Compiling rustc_codegen_ssa v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_codegen_ssa)
   Compiling rustc_resolve v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_resolve)
   Compiling rustc_trait_selection v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_trait_selection)
   Compiling rustc_lint v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_lint)
   Compiling rustc_const_eval v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_const_eval)
   Compiling rustc_ty_utils v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_ty_utils)
   Compiling rustc_traits v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_traits)
   Compiling rustc_mir_build v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_mir_build)
   Compiling rustc_codegen_llvm v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_codegen_llvm)
   Compiling rustc_typeck v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_typeck)
   Compiling rustc_plugin_impl v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_plugin_impl)
   Compiling rustc_mir_transform v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_mir_transform)
   Compiling rustc_borrowck v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_borrowck)
   Compiling rustc_privacy v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_privacy)
   Compiling rustc_interface v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_interface)
   Compiling rustc_driver v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_driver)
   Compiling rustc-main v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc)
    Finished release [optimized] target(s) in 5m 05s
Copying stage0 rustc from stage0 (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc / x86_64-pc-windows-msvc)
Assembling stage1 compiler (x86_64-pc-windows-msvc)
Building stage1 std artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
   Compiling compiler_builtins v0.1.73
   Compiling core v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\core)
   Compiling libc v0.2.126
   Compiling cc v1.0.69
   Compiling memchr v2.4.1
   Compiling std v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\std)
   Compiling unwind v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\unwind)
   Compiling rustc-std-workspace-core v1.99.0 (G:\Users\Chase\Code\Rust\rust\library\rustc-std-workspace-core)
   Compiling alloc v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\alloc)
   Compiling cfg-if v0.1.10
   Compiling adler v0.2.3
   Compiling rustc-demangle v0.1.21
error: internal compiler error: compiler\rustc_codegen_llvm\src\type_of.rs:146:13: layout: TyAndLayout {
                                    ty: rustc_std_workspace_core::result::Result<usize, rustc_std_workspace_core::fmt::Error>,
                                    layout: Layout {
                                        fields: Arbitrary {
                                            offsets: [
                                                Size(8 bytes),
                                            ],
                                            memory_index: [
                                                0,
                                            ],
                                        },
                                        variants: Single {
                                            index: 1,
                                        },
                                        abi: Aggregate {
                                            sized: true,
                                        },
                                        largest_niche: None,
                                        align: AbiAndPrefAlign {
                                            abi: Align(1 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        size: Size(2 bytes),
                                    },
                                } stride: Size(2 bytes) offset: Size(8 bytes)

thread 'rustc' panicked at 'Box<dyn Any>', G:\Users\Chase\Code\Rust\rust\compiler\rustc_errors\src\lib.rs:1334:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   2: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle::ty::fold::FallibleTypeFolder>::try_fold_binder::<rustc_middle::ty::sty::FnSig>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_codegen_llvm::type_of::struct_llfields
   8: <rustc_target::abi::TyAndLayout<rustc_middle::ty::Ty> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type
   9: <rustc_codegen_ssa::mir::place::PlaceRef<&rustc_codegen_llvm::llvm_::ffi::Value>>::project_downcast::<rustc_codegen_llvm::builder::Builder>
  10: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::Builder>>::codegen_place
  11: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  12: rustc_codegen_ssa::base::codegen_instance::<rustc_codegen_llvm::builder::Builder>
  13: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define::<rustc_codegen_llvm::builder::Builder>
  14: rustc_codegen_llvm::base::compile_codegen_unit
  15: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtNtNtCs2vb4bKWGfvL_10rustc_span6symbol6SymbolINtCs4wqBg0PzBnM_17rustc_codegen_s
  16: rustc_codegen_llvm::base::compile_codegen_unit
  17: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  19: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  20: rustc_interface::passes::start_codegen
  21: RINvMs_NtCs6lxe6u1d1HN_15rustc_interface6passesNtB5_12QueryContext5enterNCNCNvMs0_NtB7_7queriesNtB1i_7Queries15ongoing_codegen00INtNtCs9qroIgEvBu5_4core6result6ResultINtNtCs4fCcauHRDzO_5alloc5boxed3BoxDNtNtB27_3any3AnyEL_ENtCslxr0cr2Vr2Y_12rustc_errors15E
  22: <rustc_interface::queries::Query<alloc::boxed::Box<dyn core::any::Any>>>::compute::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}>
  23: RINvMs2_NtCs6lxe6u1d1HN_15rustc_interface7queriesNtNtB8_9interface8Compiler5enterNCNCNvCsg2BpsMvkavS_12rustc_driver12run_compilers_0s0_0INtNtCs9qroIgEvBu5_4core6result6ResultINtNtB2f_6option6OptionNtB6_6LinkerENtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuarante
  24: RINvCs2vb4bKWGfvL_10rustc_span15with_source_mapINtNtCs9qroIgEvBu5_4core6result6ResultuNtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuaranteedENCINvNtCs6lxe6u1d1HN_15rustc_interface9interface23create_compiler_and_runBJ_NCNvCsg2BpsMvkavS_12rustc_driver12run_compile
  25: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  26: RINvMs_CslsHbb2RadMK_10scoped_tlsINtB5_9ScopedKeyNtCs2vb4bKWGfvL_10rustc_span14SessionGlobalsE3setNCINvNtCs6lxe6u1d1HN_15rustc_interface9interface12run_compilerINtNtCs9qroIgEvBu5_4core6result6ResultuNtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuaranteedENCNvCsg2
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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.63.0-dev running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Z unstable-options -Z randomize-layout -C symbol-mangling-version=legacy -Z unstable-options -Z unstable-options -Z macro-backtrace -C target-feature=+crt-static -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -C embed-bitcode=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked

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

query stack during panic:
end of query stack
error: could not compile `rustc-demangle`

Caused by:
  process didn't exit successfully: `G:\Users\Chase\Code\Rust\rust\build\bootstrap\debug\rustc --crate-name rustc_demangle C:\Users\Chase\.cargo\registry\src\github.com-1ecc6299db9ec823\rustc-demangle-0.1.21\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 --cfg "feature=\"compiler_builtins\"" --cfg "feature=\"core\"" --cfg "feature=\"rustc-dep-of-std\"" -Zunstable-options --check-cfg names() --check-cfg values() -C metadata=4d891bf2cbe595ae -C extra-filename=-4d891bf2cbe595ae --out-dir G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps --target x86_64-pc-windows-msvc -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\release\deps --extern compiler_builtins=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\libcompiler_builtins-2c6af95dce564732.rmeta --extern core=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\librustc_std_workspace_core-710036e409e62f0d.rmeta --cap-lints allow -Z randomize-layout -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(freebsd12) --check-cfg=values(backtrace_in_libstd) "--check-cfg=values(target_env,\"libnx\")" "--check-cfg=values(target_os,\"watchos\")" "--check-cfg=values(target_arch,\"asmjs\",\"spirv\",\"nvptx\",\"nvptx64\",\"le32\",\"xtensa\")" --check-cfg=values(dont_compile_me) -Zmacro-backtrace -Ctarget-feature=+crt-static -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Cembed-bitcode=yes "-Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\")" -Z binary-dep-depinfo` (exit code: 0x80000003)
warning: build failed, waiting for other jobs to finish...
error: internal compiler error: compiler\rustc_codegen_llvm\src\type_of.rs:146:13: layout: TyAndLayout {
                                    ty: core::result::Result<usize, core::alloc::LayoutError>,
                                    layout: Layout {
                                        fields: Arbitrary {
                                            offsets: [
                                                Size(8 bytes),
                                            ],
                                            memory_index: [
                                                0,
                                            ],
                                        },
                                        variants: Single {
                                            index: 1,
                                        },
                                        abi: Aggregate {
                                            sized: true,
                                        },
                                        largest_niche: None,
                                        align: AbiAndPrefAlign {
                                            abi: Align(1 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        size: Size(2 bytes),
                                    },
                                } stride: Size(2 bytes) offset: Size(8 bytes)

thread 'rustc' panicked at 'Box<dyn Any>', G:\Users\Chase\Code\Rust\rust\compiler\rustc_errors\src\lib.rs:1334:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   2: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   3: <rustc_errors::Handler>::bug::<&alloc::string::String>
   4: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle::ty::fold::FallibleTypeFolder>::try_fold_binder::<rustc_middle::ty::sty::FnSig>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_codegen_llvm::type_of::struct_llfields
   8: <rustc_target::abi::TyAndLayout<rustc_middle::ty::Ty> as rustc_codegen_llvm::type_of::LayoutLlvmExt>::llvm_type
   9: <rustc_codegen_ssa::mir::place::PlaceRef<&rustc_codegen_llvm::llvm_::ffi::Value>>::project_downcast::<rustc_codegen_llvm::builder::Builder>
  10: <rustc_codegen_ssa::mir::FunctionCx<rustc_codegen_llvm::builder::Builder>>::codegen_place
  11: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
  12: rustc_codegen_ssa::base::codegen_instance::<rustc_codegen_llvm::builder::Builder>
  13: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define::<rustc_codegen_llvm::builder::Builder>
  14: rustc_codegen_llvm::base::compile_codegen_unit
  15: RINvXNtCscInEZjIJEzE_12rustc_middle9dep_graphNtNtB3_8dep_node7DepKindNtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph7DepKind9with_depsNCINvMs1_NtB17_5graphINtB2i_8DepGraphBH_E14with_task_implNtNtNtB5_2ty7context6TyCtxtNtNtCs2vb4bKWGfvL_10rustc_span6symbo
  16: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtNtNtCs2vb4bKWGfvL_10rustc_span6symbol6SymbolINtCs4wqBg0PzBnM_17rustc_codegen_s
  17: rustc_codegen_llvm::base::compile_codegen_unit
  18: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  19: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  20: <rustc_session::session::Session>::time::<alloc::boxed::Box<dyn core::any::Any>, rustc_interface::passes::start_codegen::{closure#0}>
  21: rustc_interface::passes::start_codegen
  22: RINvMs_NtCs6lxe6u1d1HN_15rustc_interface6passesNtB5_12QueryContext5enterNCNCNvMs0_NtB7_7queriesNtB1i_7Queries15ongoing_codegen00INtNtCs9qroIgEvBu5_4core6result6ResultINtNtCs4fCcauHRDzO_5alloc5boxed3BoxDNtNtB27_3any3AnyEL_ENtCslxr0cr2Vr2Y_12rustc_errors15E
  23: <rustc_interface::queries::Query<alloc::boxed::Box<dyn core::any::Any>>>::compute::<<rustc_interface::queries::Queries>::ongoing_codegen::{closure#0}>
  24: RINvMs2_NtCs6lxe6u1d1HN_15rustc_interface7queriesNtNtB8_9interface8Compiler5enterNCNCNvCsg2BpsMvkavS_12rustc_driver12run_compilers_0s0_0INtNtCs9qroIgEvBu5_4core6result6ResultINtNtB2f_6option6OptionNtB6_6LinkerENtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuarante
  25: RINvCs2vb4bKWGfvL_10rustc_span15with_source_mapINtNtCs9qroIgEvBu5_4core6result6ResultuNtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuaranteedENCINvNtCs6lxe6u1d1HN_15rustc_interface9interface23create_compiler_and_runBJ_NCNvCsg2BpsMvkavS_12rustc_driver12run_compile
  26: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  27: RINvMs_CslsHbb2RadMK_10scoped_tlsINtB5_9ScopedKeyNtCs2vb4bKWGfvL_10rustc_span14SessionGlobalsE3setNCINvNtCs6lxe6u1d1HN_15rustc_interface9interface12run_compilerINtNtCs9qroIgEvBu5_4core6result6ResultuNtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuaranteedENCNvCsg2
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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.63.0-dev running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Z unstable-options -C incremental -Z randomize-layout -C symbol-mangling-version=legacy -Z unstable-options -Z unstable-options -Z macro-backtrace -C target-feature=+crt-static -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -C embed-bitcode=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked

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

query stack during panic:
end of query stack
error: could not compile `alloc`

Caused by:
  process didn't exit successfully: `G:\Users\Chase\Code\Rust\rust\build\bootstrap\debug\rustc --crate-name alloc --edition=2021 library\alloc\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Zunstable-options --check-cfg names() --check-cfg values() -C metadata=44eda8c292567317 -C extra-filename=-44eda8c292567317 --out-dir G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps --target x86_64-pc-windows-msvc -C incremental=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\incremental -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\release\deps --extern compiler_builtins=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\libcompiler_builtins-2c6af95dce564732.rmeta --extern core=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\libcore-a73f3dcab1ae4e39.rmeta -Z randomize-layout -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(freebsd12) --check-cfg=values(backtrace_in_libstd) "--check-cfg=values(target_env,\"libnx\")" "--check-cfg=values(target_os,\"watchos\")" "--check-cfg=values(target_arch,\"asmjs\",\"spirv\",\"nvptx\",\"nvptx64\",\"le32\",\"xtensa\")" --check-cfg=values(dont_compile_me) -Zmacro-backtrace -Ctarget-feature=+crt-static -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Cembed-bitcode=yes "-Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\")" -Z binary-dep-depinfo` (exit code: 0x80000003)
Build completed unsuccessfully in 0:06:02

Edit: This may just be another overzealous check

Edit 2: Actually the check is fine, I just need to figure out how to properly handle situations where offset > layout.size but I'm not sure how to, could I have some help on that?

@eddyb
Copy link
Member

eddyb commented Jun 13, 2022

@Kixiron Looks like the layout is invalid: you can't have field offsets (or, well, field_offset + field_size) greater than the size (they would be out of bounds).

My best guess is the niche optimization assumes that only the "dataful" variant can contribute to the size of the enum, but not the rest. You might need to copy some kind of looping over all the variants used in the tag representation, to the niche optimization, to compute a maximum size, but I'm not really clear on why the variant with the field out of bounds has the mismatched size.

@Kixiron
Copy link
Member Author

Kixiron commented Jun 14, 2022

New day, new ICE

I fixed the field offset thing, I was saving the offset value before I was calculating the extra padding, whoops
New problem: I get an ice from invalid field access on immediate values, it looks like we currently don't have handling for when a value has padding in front of it or something. I'm gonna need some help here, I have no idea what should be done to fix this
Icy Code

Backtrace
 λ  x test
Updating only changed submodules
  Submodules updated in 0.08 seconds
Building rustbuild
   Compiling bootstrap v0.0.0 (G:\Users\Chase\Code\Rust\rust\src\bootstrap)
    Finished dev [unoptimized] target(s) in 7.14s
Building stage0 tool tidy (x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.41s
tidy check
* 630 error codes
* highest error code: E0788
Checking which error codes lack tests...
* 378 features
Found 505 error codes
Found 0 error(s) in error codes
Done!
fmt check
Building stage0 std artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.62s
Copying stage0 std from stage0 (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc / x86_64-pc-windows-msvc)
Building stage0 compiler artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
   Compiling rustc_llvm v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_llvm)
   Compiling rustc_codegen_llvm v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_codegen_llvm)
   Compiling rustc_interface v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_interface)
   Compiling rustc_driver v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_driver)
   Compiling rustc-main v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc)
    Finished release [optimized] target(s) in 7m 56s
Copying stage0 rustc from stage0 (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc / x86_64-pc-windows-msvc)
Assembling stage1 compiler (x86_64-pc-windows-msvc)
Building stage1 std artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
   Compiling compiler_builtins v0.1.73
   Compiling core v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\core)
   Compiling libc v0.2.126
   Compiling cc v1.0.69
   Compiling memchr v2.4.1
   Compiling std v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\std)
   Compiling unwind v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\unwind)
error: internal compiler error: compiler\rustc_const_eval\src\interpret\operand.rs:438:18: invalid field access on immediate (0x0001, 0x00): (u16, bool), layout TyAndLayout {
                                    ty: (u16, bool),
                                    layout: Layout {
                                        fields: Arbitrary {
                                            offsets: [
                                                Size(2 bytes),
                                                Size(3 bytes),
                                            ],
                                            memory_index: [
                                                0,
                                                1,
                                            ],
                                        },
                                        variants: Single {
                                            index: 0,
                                        },
                                        abi: Aggregate {
                                            sized: true,
                                        },
                                        largest_niche: Some(
                                            Niche {
                                                offset: Size(2 bytes),
                                                value: Int(
                                                    I8,
                                                    false,
                                                ),
                                                valid_range: 0..=1,
                                            },
                                        ),
                                        align: AbiAndPrefAlign {
                                            abi: Align(2 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        size: Size(4 bytes),
                                    },
                                }
   --> library\core\src\mem\valid_align.rs:125:19
    |
125 |     _Align1Shl0 = 1 << 0,
    |                   ^^^^^^

thread 'rustc' panicked at 'Box<dyn Any>', G:\Users\Chase\Code\Rust\rust\compiler\rustc_errors\src\lib.rs:1274:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::Handler>::span_err::<rustc_span::span_encoding::Span, &str>
   2: <rustc_errors::Handler>::span_err::<rustc_span::span_encoding::Span, &str>
   3: <rustc_errors::Handler>::span_bug::<rustc_span::span_encoding::Span, &alloc::string::String>
   4: rustc_const_eval::transform::check_consts::qualifs::in_operand::<rustc_const_eval::transform::check_consts::qualifs::NeedsDrop, <rustc_const_eval::transform::check_consts::resolver::TransferFunction<rustc_const_eval::transform::check_consts::qualifs::NeedsDrop> as rustc_middle::mir::visit::Visitor>::visit_terminator::{closure#0}>
   5: rustc_const_eval::transform::check_consts::qualifs::in_operand::<rustc_const_eval::transform::check_consts::qualifs::NeedsDrop, <rustc_const_eval::transform::check_consts::resolver::TransferFunction<rustc_const_eval::transform::check_consts::qualifs::NeedsDrop> as rustc_middle::mir::visit::Visitor>::visit_terminator::{closure#0}>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::operand_field
   8: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::operand_projection
   9: RINvXs_NtNtNtCs9qroIgEvBu5_4core4iter8adapters6copiedINtB5_6CopiedINtNtNtBb_5slice4iter4IterINtNtCscInEZjIJEzE_12rustc_middle3mir14ProjectionElemNtB1v_5LocalNtNtB1x_2ty2TyEEENtNtNtB9_6traits8iterator8Iterator8try_foldNtNtNtCshqJ9Ba8i3JL_16rustc_const_eval
  10: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::eval_place_to_op
  11: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::eval_place_to_op
  12: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::run
  13: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
  14: RINvXNtCscInEZjIJEzE_12rustc_middle9dep_graphNtNtB3_8dep_node7DepKindNtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph7DepKind9with_depsNCINvMs1_NtB17_5graphINtB2i_8DepGraphBH_E14with_task_implNtNtNtB5_2ty7context6TyCtxtINtB38_11ParamEnvAndNtNtNtB5_3mir9in
  15: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtINtB2r_11ParamEnvAndNtNtNtB1j_3mir9interpret8GlobalIdEINtNtCs9qroIgEvBu5_4core
  16: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::eval_to_allocation_raw, rustc_query_impl::plumbing::QueryCtxt>
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_mark_green
  18: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
  19: RINvXNtCscInEZjIJEzE_12rustc_middle9dep_graphNtNtB3_8dep_node7DepKindNtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph7DepKind9with_depsNCINvMs1_NtB17_5graphINtB2i_8DepGraphBH_E14with_task_implNtNtNtB5_2ty7context6TyCtxtINtB38_11ParamEnvAndNtNtNtB5_3mir9in
  20: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtINtB2r_11ParamEnvAndNtNtNtB1j_3mir9interpret8GlobalIdEINtNtCs9qroIgEvBu5_4core
  21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::eval_to_const_value_raw, rustc_query_impl::plumbing::QueryCtxt>
  22: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_mark_green
  23: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
  24: RINvXNtCscInEZjIJEzE_12rustc_middle9dep_graphNtNtB3_8dep_node7DepKindNtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph7DepKind9with_depsNCINvMs1_NtB17_5graphINtB2i_8DepGraphBH_E14with_task_implNtNtNtB5_2ty7context6TyCtxtINtB38_11ParamEnvAndNtNtNtB5_3mir9in
  25: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtINtB2r_11ParamEnvAndNtNtNtB1j_3mir9interpret8GlobalIdEINtNtCs9qroIgEvBu5_4core
  26: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::eval_to_const_value_raw, rustc_query_impl::plumbing::QueryCtxt>
  27: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_mark_green
  28: <rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  29: <rustc_middle::ty::context::TyCtxt>::const_eval_poly
  30: <rustc_typeck::collect::ItemCtxt>::bound_defines_assoc_item
  31: <rustc_typeck::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_item
  32: <rustc_middle::hir::map::Map>::deep_visit_item_likes_in_module::<rustc_typeck::collect::CollectItemTypesVisitor>
  33: RNvXNvNtCsbXJ7WfxSejG_12rustc_typeck6errors119__DERIVE_rustc_session_SessionDiagnostic_session_diagnostic_sess_rustc_errors_ErrorGuaranteed_FOR_SubstsOnOverriddenImplNtB4_22SubstsOnOverriddenImplNtNtCsjCzBQpETHRl_13rustc_session7session17SessionDiagnostic
  34: RINvXNtCscInEZjIJEzE_12rustc_middle9dep_graphNtNtB3_8dep_node7DepKindNtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph7DepKind9with_depsNCINvMs1_NtB17_5graphINtB2i_8DepGraphBH_E14with_task_implNtNtNtB5_2ty7context6TyCtxtINtNtCs9qroIgEvBu5_4core6option6Opti
  35: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtNtNtCs2vb4bKWGfvL_10rustc_span6def_id10LocalDefIduECs590zEwioTEG_16rustc_query
  36: rustc_query_system::query::plumbing::force_query::<rustc_query_impl::queries::trait_def, rustc_query_impl::plumbing::QueryCtxt>
  37: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_mod_item_types, rustc_query_impl::plumbing::QueryCtxt>
  38: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_mark_green
  39: <rustc_middle::hir::map::Map>::for_each_module::<rustc_typeck::check_crate::{closure#0}::{closure#0}::{closure#0}>
  40: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#0}, ()>
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: RINvXNtCscInEZjIJEzE_12rustc_middle9dep_graphNtNtB3_8dep_node7DepKindNtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph7DepKind9with_depsNCINvMs1_NtB17_5graphINtB2i_8DepGraphBH_E14with_task_implNtNtNtB5_2ty7context6TyCtxtuINtNtCs9qroIgEvBu5_4core6option6Opt
  44: RINvMs1_NtNtCs1LEY3TOdXnz_18rustc_query_system9dep_graph5graphINtB6_8DepGraphNtNtNtCscInEZjIJEzE_12rustc_middle9dep_graph8dep_node7DepKindE9with_taskNtNtNtB1j_2ty7context6TyCtxtuINtNtCs9qroIgEvBu5_4core6option6OptionNtNtNtCsfSnYSweX8G0_9rustc_ast6expand9a
  45: rustc_query_system::query::plumbing::force_query::<rustc_query_impl::queries::trait_def, rustc_query_impl::plumbing::QueryCtxt>
  46: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  47: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_mark_green
  48: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  49: RINvMs2_NtCs6lxe6u1d1HN_15rustc_interface7queriesNtNtB8_9interface8Compiler5enterNCNCNvCsg2BpsMvkavS_12rustc_driver12run_compilers_0s0_0INtNtCs9qroIgEvBu5_4core6result6ResultINtNtB2f_6option6OptionNtB6_6LinkerENtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuarante
  50: RINvCs2vb4bKWGfvL_10rustc_span15with_source_mapINtNtCs9qroIgEvBu5_4core6result6ResultuNtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuaranteedENCINvNtCs6lxe6u1d1HN_15rustc_interface9interface23create_compiler_and_runBJ_NCNvCsg2BpsMvkavS_12rustc_driver12run_compile
  51: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
  52: RINvMs_CslsHbb2RadMK_10scoped_tlsINtB5_9ScopedKeyNtCs2vb4bKWGfvL_10rustc_span14SessionGlobalsE3setNCINvNtCs6lxe6u1d1HN_15rustc_interface9interface12run_compilerINtNtCs9qroIgEvBu5_4core6result6ResultuNtCslxr0cr2Vr2Y_12rustc_errors15ErrorGuaranteedENCNvCsg2
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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.63.0-dev running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Z unstable-options -C incremental -C symbol-mangling-version=legacy -Z unstable-options -Z unstable-options -Z macro-backtrace -C target-feature=+crt-static -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -C embed-bitcode=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked

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

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `mem::valid_align::ValidAlignEnum16::_Align1Shl0::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `mem::valid_align::ValidAlignEnum16::_Align1Shl0::{constant#0}`
#2 [eval_to_const_value_raw] simplifying constant for the type system `mem::valid_align::ValidAlignEnum16::_Align1Shl0::{constant#0}`
#3 [collect_mod_item_types] collecting item types in module `mem::valid_align`
#4 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `core`

Caused by:
  process didn't exit successfully: `G:\Users\Chase\Code\Rust\rust\build\bootstrap\debug\rustc --crate-name core --edition=2021 library\core\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Zunstable-options --check-cfg names() --check-cfg values() -C metadata=a73f3dcab1ae4e39 -C extra-filename=-a73f3dcab1ae4e39 --out-dir G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps --target x86_64-pc-windows-msvc -C incremental=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\incremental -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\release\deps -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(freebsd12) --check-cfg=values(backtrace_in_libstd) "--check-cfg=values(target_env,\"libnx\")" "--check-cfg=values(target_os,\"watchos\")" "--check-cfg=values(target_arch,\"asmjs\",\"spirv\",\"nvptx\",\"nvptx64\",\"le32\",\"xtensa\")" --check-cfg=values(dont_compile_me) -Zmacro-backtrace -Ctarget-feature=+crt-static -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Cembed-bitcode=yes "-Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\")" -Z binary-dep-depinfo` (exit code: 0x80000003)
Build completed unsuccessfully in 0:08:30

@rust-log-analyzer

This comment has been minimized.

@eddyb
Copy link
Member

eddyb commented Jun 27, 2022

ICE from #97861 (comment) is:

error: internal compiler error: compiler\rustc_const_eval\src\interpret\operand.rs:438:18:
    invalid field access on immediate (0x0001, 0x00): (u16, bool), layout TyAndLayout {
...
                                        fields: Arbitrary {
                                            offsets: [
                                                Size(2 bytes),
                                                Size(3 bytes),
                                            ],
...
                                        abi: Aggregate {
                                            sized: true,
                                        },
...

That's miri (I wish the crate wasn't named rustc_const_eval but alas), and it looks like it thinks Rust pairs are always immediates, even if the layout abi isn't Abi::ScalarPair but Abi::Aggregate.

Oh I see, it's the checked arithmetic MIR operators, which return (T, bool) - surprised codegen can handle this, I guess it's because codegen unpacks the LLVM pair and creates a Rust pair instead?

cc @oli-obk @RalfJung Could miri easily treat the (T, bool) checked arithmetic result type as having unknown layout and use general-purpose field-wise initialization to write back the result?
(In this case, the randomization decided to add 2 bytes of padding before the first field)

@oli-obk
Copy link
Contributor

oli-obk commented Jun 27, 2022

Could miri easily treat the (T, bool) checked arithmetic result type as having unknown layout and use general-purpose field-wise initialization to write back the result?

We may end up getting into whack-a-mole territory by just fixing checked arithmethic, there are a lot of things like wide pointers that are pretty much hardcoded to be pairs.

Maybe write_immediate should unpack pairs and write each element individually... Though the main problem I see is that it gets expensive really fast to always write pairs individually, as that'll make them all go through an allocation instead of using the pair optimization.

@eddyb
Copy link
Member

eddyb commented Jun 27, 2022

We may end up getting into whack-a-mole territory by just fixing checked arithmethic, there are a lot of things like wide pointers that are pretty much hardcoded to be pairs.

That's a different kind of pair - wide pointers will continue to be Abi::ScalarPair and not have their field offsets randomized at all. What this PR affects is types like (T, U), and they cease to be Abi::ScalarPair once their offsets stop matching the ones required for Abi::ScalarPair.

AFAIK checked arithmetic is a rare case of tuple types being used implicitly in MIR.

@RalfJung
Copy link
Member

Could miri easily treat the (T, bool) checked arithmetic result type as having unknown layout and use general-purpose field-wise initialization to write back the result?

Not easily, no. In fact checked arithmetic is one of the primary reasons why Miri has intermediate scalar pairs to begin with. I would strongly prefer to keep it that way.

Scalar pairs can have padding, so why does randomize-layout make them general aggregates here?

@oli-obk
Copy link
Contributor

oli-obk commented Jun 27, 2022

In order to keep our performance in regular const eval, we could just make a decision based on whether randomize-layout is set or not. I don't see a good way to generalize this right now without overcomplicating miri's place logic (I tried this before, it did not go very well).

@RalfJung
Copy link
Member

Oh, leading padding. Yeah that's annoying.

checked arithmetic is a rare case of tuple types being used implicitly in MIR.

I could imagine that just something specific for checked arithmetic might actually work fairly reasonably. At least I have an idea.^^ I'll put it on my list.

@eddyb
Copy link
Member

eddyb commented Jun 27, 2022

Scalar pairs can have padding, so why does randomize-layout make them general aggregates here?

To be clear, scalar pairs must have the exact layout of a #[repr(C)] struct Pair<A, B>(A, B); for any two scalars A and B (as the scalars are accessed by offset). Anything else is treated as a general aggregate.

Now we could extend this, as unlike Abi::Scalar/Abi::Vector, there is no #[repr(transparent)] and non-Rust call ABI interaction with Abi::ScalarPair (i.e. it's treated like Abi::Aggregate for those purposes).

One might imagine even something like an immediate_leaves: Option<ArrayVec<(Size, Scalar | Vector), N>> field in Abi::Aggregate, to allow passing N (2, or larger if we feel like it) components around, instead of the aggregate as a whole - we would have to keep track of the offsets though, and use them to determine which leaves to keep at any given time.

(bonus: this would also work for e.g. #[repr(C)] struct Foo(u8);, which isn't allowed to be Abi::Scalar, and immediate_leaves: Some([]) would be a ZST)

EDIT: I might try playing around with this, or at least going for the "explicit offsets", might even be an optimization over recomputing them all the time.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Aug 7, 2022

☔ The latest upstream changes (presumably #99983) made this pull request unmergeable. Please resolve the merge conflicts.

@Kixiron
Copy link
Member Author

Kixiron commented Dec 1, 2022

So this feels like it should be working (or at least there's no problems I'm immediately aware of) but I'm getting some llvm bitcode errors

Build Log
 λ  $env:RUSTFLAGS_NOT_BOOTSTRAP = "-Z randomize-layout"
 λ  x test library/core
Building rustbuild
    Finished dev [unoptimized] target(s) in 0.10s
Building stage0 std artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
    Finished release [optimized] target(s) in 0.42s
Copying stage0 std from stage0 (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc / x86_64-pc-windows-msvc)
Building stage0 compiler artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
   Compiling rustc_abi v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_abi)
   Compiling rustc_target v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_target)
   Compiling rustc_hir v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_hir)
   Compiling rustc_lint_defs v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_lint_defs)
   Compiling rustc_hir_pretty v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_hir_pretty)
   Compiling rustc_errors v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_errors)
   Compiling rustc_session v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_session)
   Compiling rustc_attr v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_attr)
   Compiling rustc_query_system v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_query_system)
   Compiling rustc_parse v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_parse)
   Compiling rustc_middle v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_middle)
   Compiling rustc_ast_passes v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_ast_passes)
   Compiling rustc_expand v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_expand)
   Compiling rustc_builtin_macros v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_builtin_macros)
   Compiling rustc_infer v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_infer)
   Compiling rustc_mir_dataflow v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_mir_dataflow)
   Compiling rustc_metadata v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_metadata)
   Compiling rustc_incremental v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_incremental)
   Compiling rustc_symbol_mangling v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_symbol_mangling)
   Compiling rustc_query_impl v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_query_impl)
   Compiling rustc_monomorphize v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_monomorphize)
   Compiling rustc_ast_lowering v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_ast_lowering)
   Compiling rustc_passes v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_passes)
   Compiling rustc_save_analysis v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_save_analysis)
   Compiling rustc_resolve v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_resolve)
   Compiling rustc_transmute v0.1.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_transmute)
   Compiling rustc_trait_selection v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_trait_selection)
   Compiling rustc_const_eval v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_const_eval)
   Compiling rustc_lint v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_lint)
   Compiling rustc_traits v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_traits)
   Compiling rustc_ty_utils v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_ty_utils)
   Compiling rustc_mir_build v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_mir_build)
   Compiling rustc_hir_analysis v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_hir_analysis)
   Compiling rustc_plugin_impl v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_plugin_impl)
   Compiling rustc_codegen_ssa v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_codegen_ssa)
   Compiling rustc_mir_transform v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_mir_transform)
   Compiling rustc_hir_typeck v0.1.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_hir_typeck)
   Compiling rustc_privacy v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_privacy)
   Compiling rustc_borrowck v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_borrowck)
   Compiling rustc_codegen_llvm v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_codegen_llvm)
   Compiling rustc_interface v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_interface)
   Compiling rustc_driver v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_driver)
   Compiling rustc_smir v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc_smir)
   Compiling rustc-main v0.0.0 (G:\Users\Chase\Code\Rust\rust\compiler\rustc)
    Finished release [optimized] target(s) in 2m 52s
Copying stage0 rustc from stage0 (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc / x86_64-pc-windows-msvc)
Assembling stage1 compiler (x86_64-pc-windows-msvc)
Building stage1 std artifacts (x86_64-pc-windows-msvc -> x86_64-pc-windows-msvc)
   Compiling compiler_builtins v0.1.84
   Compiling core v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\core)
   Compiling libc v0.2.135
   Compiling cc v1.0.76
   Compiling memchr v2.5.0
   Compiling std v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\std)
   Compiling unwind v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\unwind)
   Compiling rustc-std-workspace-core v1.99.0 (G:\Users\Chase\Code\Rust\rust\library\rustc-std-workspace-core)
   Compiling alloc v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\alloc)
   Compiling cfg-if v1.0.0
   Compiling adler v1.0.2
   Compiling rustc-demangle v0.1.21
   Compiling rustc-std-workspace-alloc v1.99.0 (G:\Users\Chase\Code\Rust\rust\library\rustc-std-workspace-alloc)
   Compiling panic_abort v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\panic_abort)
   Compiling panic_unwind v0.0.0 (G:\Users\Chase\Code\Rust\rust\library\panic_unwind)
   Compiling gimli v0.26.1
   Compiling miniz_oxide v0.5.3
   Compiling hashbrown v0.12.3
   Compiling object v0.29.0
   Compiling std_detect v0.1.5 (G:\Users\Chase\Code\Rust\rust\library\stdarch\crates\std_detect)
error: failed to parse bitcode for LTO module: Invalid cast (Producer: 'LLVM15.0.4-rust-1.67.0-nightly' Reader: 'LLVM 15.0.4-rust-1.67.0-nightly')

error: could not compile `miniz_oxide` due to previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `alloc`

Caused by:
  process didn't exit successfully: `G:\Users\Chase\Code\Rust\rust\build\bootstrap\debug\rustc --crate-name alloc --edition=2021 library\alloc\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=0 -Zunstable-options --check-cfg names() --check-cfg values() -C metadata=b18f453917815b89 -C extra-filename=-b18f453917815b89 --out-dir G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps --target x86_64-pc-windows-msvc -C incremental=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\incremental -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps -L dependency=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\release\deps --extern compiler_builtins=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\libcompiler_builtins-7f32e1d8db5bf5b8.rmeta --extern core=G:\Users\Chase\Code\Rust\rust\build\x86_64-pc-windows-msvc\stage1-std\x86_64-pc-windows-msvc\release\deps\libcore-7a8ae34f67ccc69f.rmeta -Z randomize-layout -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options --check-cfg=values(bootstrap) --check-cfg=values(stdarch_intel_sde) --check-cfg=values(no_fp_fmt_parse) --check-cfg=values(no_global_oom_handling) --check-cfg=values(no_rc) --check-cfg=values(no_sync) --check-cfg=values(freebsd12) --check-cfg=values(backtrace_in_libstd) "--check-cfg=values(target_env,\"libnx\")" "--check-cfg=values(target_os,\"watchos\")" "--check-cfg=values(target_arch,\"asmjs\",\"spirv\",\"nvptx\",\"nvptx64\",\"le32\",\"xtensa\")" --check-cfg=values(dont_compile_me) --check-cfg=values(rustix_use_libc) -Zmacro-backtrace -Csplit-debuginfo=packed -Ctarget-feature=+crt-static -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Cembed-bitcode=yes "-Zcrate-attr=doc(html_root_url=\"https://doc.rust-lang.org/nightly/\")" -Z binary-dep-depinfo` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
Build completed unsuccessfully in 0:03:43

@rust-log-analyzer

This comment has been minimized.

@the8472
Copy link
Member

the8472 commented Dec 3, 2022

Enabling LLVM asserts, disabling LTO and only building with 1 job gets me this

$ RUSTC_WRAPPER="" RUSTFLAGS_NOT_BOOTSTRAP="-Z randomize-layout -Clto=off" ./x test -j 1 library/core/ --stage 1
Building rustbuild
    Finished dev [unoptimized] target(s) in 0.11s
Building stage0 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.22s
Copying stage0 std from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Building stage0 compiler artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
    Finished release [optimized + debuginfo] target(s) in 0.26s
Copying stage0 rustc from stage0 (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu / x86_64-unknown-linux-gnu)
Assembling stage1 compiler (x86_64-unknown-linux-gnu)
Building stage1 std artifacts (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
   Compiling alloc v0.0.0 (/home/the8472/workspace/rust/library/alloc)
rustc: /checkout/src/llvm-project/llvm/lib/IR/Instructions.cpp:3301: static llvm::CastInst *llvm::CastInst::CreatePointerCast(llvm::Value *, llvm::Type *, const llvm::Twine &, llvm::Instruction *): Assertion `(Ty->isIntOrIntVectorTy() || Ty->isPtrOrPtrVectorTy()) && "Invalid cast"' failed.
rustc exited with signal: 6 (SIGABRT) (core dumped)
error: could not compile `alloc`

Caused by:
  process didn't exit successfully: `/home/the8472/workspace/rust/build/bootstrap/debug/rustc --crate-name alloc --edition=2021 library/alloc/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="compiler-builtins-c"' -Zunstable-options --check-cfg 'names()' --check-cfg 'values()' -C metadata=858e087d7442830c -C extra-filename=-858e087d7442830c --out-dir /home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -C incremental=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/incremental -L dependency=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/release/deps --extern compiler_builtins=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcompiler_builtins-2a5cebab717a8c68.rmeta --extern core=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps/libcore-230b2eaf9b4b393c.rmeta -C target-cpu=native -Z randomize-layout -Clto=off -Csymbol-mangling-version=legacy -Zunstable-options -Zunstable-options '--check-cfg=values(bootstrap)' '--check-cfg=values(stdarch_intel_sde)' '--check-cfg=values(no_fp_fmt_parse)' '--check-cfg=values(no_global_oom_handling)' '--check-cfg=values(no_rc)' '--check-cfg=values(no_sync)' '--check-cfg=values(freebsd12)' '--check-cfg=values(backtrace_in_libstd)' '--check-cfg=values(target_env,"libnx")' '--check-cfg=values(target_os,"watchos")' '--check-cfg=values(target_arch,"asmjs","spirv","nvptx","nvptx64","le32","xtensa")' '--check-cfg=values(dont_compile_me)' '--check-cfg=values(rustix_use_libc)' -Zmacro-backtrace -Clink-args=-Wl,-z,origin '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Clink-args=-fuse-ld=lld -Csplit-debuginfo=off -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Cembed-bitcode=yes '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Z binary-dep-depinfo -L native=/home/the8472/workspace/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/build/compiler_builtins-54332b4080ab4c9b/out` (exit status: 254)
Build completed unsuccessfully in 0:00:05

@Kixiron
Copy link
Member Author

Kixiron commented Dec 9, 2022

So, what exactly is the issue going on here, I'm not really sure how to diagnose this

@the8472
Copy link
Member

the8472 commented Dec 9, 2022

It's failing in llvm when compiling alloc. Not an expert in that area, my guess is that rustc is now emitting invalid LLVM IR. Since it's about pointer casts maybe a pointer is being cast to or from a type that now has padding but shouldn't.

The dev guide has a section on LLVM debugging: https://rustc-dev-guide.rust-lang.org/backend/debugging.html

@bjorn3
Copy link
Member

bjorn3 commented Dec 10, 2022

Does this add padding to abi::ScalarPair or abi::Vector? Both have hard coded assumptions about the layout in codegen backends.

@Kixiron
Copy link
Member Author

Kixiron commented Dec 10, 2022

I'm not entirely sure, to be honest. There's a separate LayoutCalculator::scalar_pair() but the LayoutCalculator::univariant() method still has some handling for it and vectors should (?) probably have the ReprFlags::IS_SIMD flag set which inhibits randomization, but I'm not 100% sure

@Kixiron
Copy link
Member Author

Kixiron commented Dec 10, 2022

Looking into it more, that could be the issue since it looks like we decide what the type's abi is after offset calculation is done, so it may fix things to swap the order of those two Never mind, abi decisions are dependent on field offsets

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] src/test/rustdoc-ui/z-help.rs stdout ----
diff of stdout:

69         `=off` (default)
70     -Z                       instrument-mcount=val -- insert function instrument code for mcount-based tracing (default: no)
71     -Z                       keep-hygiene-data=val -- keep hygiene data after analysis (default: no)
+     -Z        layout-random-padding-max-factor=val -- set the maximum field alignment padding multiple when using 'randomize-layout' (default: 3)
72     -Z                             layout-seed=val -- seed layout randomization
73     -Z                   link-native-libraries=val -- link native libraries in the linker invocation (default: yes)
74     -Z                               link-only=val -- link the `.rlink` file generated by `-Z no-link` (default: no)

The actual stdout differed from the expected stdout.
The actual stdout differed from the expected stdout.
Actual stdout saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-ui/z-help/z-help.stdout
To only update this specific test, also pass `--test-args z-help.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
status: exit status: 0
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" "/checkout/src/test/rustdoc-ui/z-help.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-ui/z-help" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/rustdoc-ui/z-help/auxiliary" "-Zhelp"
--- stdout -------------------------------
-Z                          allow-features=val -- only allow the listed language features to be enabled in code (space separated)
    -Z                       always-encode-mir=val -- encode MIR of all functions into the crate metadata (default: no)
    -Z                            asm-comments=val -- generate comments into the assembly (may change behavior) (default: no)
    -Z                       assert-incr-state=val -- assert that the incremental cache is in given state: either `loaded` or `not-loaded`.
    -Z               assume-incomplete-release=val -- make cfg(version) treat the current version as incomplete (default: no)
    -Z                      binary-dep-depinfo=val -- include artifacts (sysroot, crate dependencies) used during compilation in dep-info (default: no)
    -Z                             box-noalias=val -- emit noalias metadata for box (default: yes)
    -Z                       branch-protection=val -- set options for branch target identification and pointer authentication on AArch64
    -Z                           cf-protection=val -- instrument control-flow architecture protection
    -Z               cgu-partitioning-strategy=val -- the codegen unit partitioning strategy to use
    -Z                                   chalk=val -- enable the experimental Chalk-based trait solving engine
    -Z                         codegen-backend=val -- the backend to use
    -Z                             combine-cgu=val -- combine CGUs into a single one
    -Z                              crate-attr=val -- inject the given attribute in the crate
    -Z                debug-info-for-profiling=val -- emit discriminators and other data necessary for AutoFDO
    -Z                            debug-macros=val -- emit line numbers debug info inside macros (default: no)
    -Z                 deduplicate-diagnostics=val -- deduplicate identical diagnostics (default: yes)
    -Z                  dep-info-omit-d-target=val -- in dep-info output, omit targets for tracking dependencies of the dep-info files themselves (default: no)
    -Z                               dep-tasks=val -- print tasks that execute and the color their dep node gets (requires debug build) (default: no)
    -Z                        diagnostic-width=val -- set the current output width for diagnostic truncation
    -Z                                 dlltool=val -- import library generation tool (windows-gnu only)
    -Z                 dont-buffer-diagnostics=val -- emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) (default: no)
    -Z                           drop-tracking=val -- enables drop tracking in generators (default: no)
    -Z                        dual-proc-macros=val -- load proc macros for both target and host, but only link to the target (default: no)
    -Z                          dump-dep-graph=val -- dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv) (default: no)
    -Z                  dump-drop-tracking-cfg=val -- dump drop-tracking control-flow graph as a `.dot` file (default: no)
    -Z                                dump-mir=val -- dump MIR state to file.
        `val` is used to select which passes and functions to dump. For example:
        `all` matches all passes and functions,
        `foo` matches all passes for functions whose name contains 'foo',
        `foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
        `foo | bar` all passes for function names containing 'foo' or 'bar'.
    -Z                       dump-mir-dataflow=val -- in addition to `.mir` files, create graphviz `.dot` files with dataflow results (default: no)
    -Z                            dump-mir-dir=val -- the directory the MIR is dumped into (default: `mir_dump`)
    -Z            dump-mir-exclude-pass-number=val -- exclude the pass number when dumping MIR (used in tests) (default: no)
    -Z                       dump-mir-graphviz=val -- in addition to `.mir` files, create graphviz `.dot` files (and with `-Z instrument-coverage`, also create a `.dot` file for the MIR-derived coverage graph) (default: no)
    -Z                       dump-mir-spanview=val -- in addition to `.mir` files, create `.html` files to view spans for all `statement`s (including terminators), only `terminator` spans, or computed `block` spans (one span encompassing a block's terminator and all statements). If `-Z instrument-coverage` is also enabled, create an additional `.html` file showing the computed coverage spans.
    -Z                           dwarf-version=val -- version of DWARF debug information to emit (default: 2 or 4, depending on platform)
    -Z                               dylib-lto=val -- enables LTO for dylib crate type
    -Z                        emit-stack-sizes=val -- emit a section containing stack size metadata (default: no)
    -Z                           emit-thin-lto=val -- emit the bc module with thin LTO info (default: yes)
    -Z               export-executable-symbols=val -- export symbols from executables, as if they were dynamic libraries
    -Z                   extra-const-ub-checks=val -- turns on more checks to detect const UB, which can be slow (default: no)
    -Z                             fewer-names=val -- reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) (default: no)
    -Z              force-unstable-if-unmarked=val -- force all crates to be `rustc_private` unstable (default: no)
    -Z                                    fuel=val -- set the optimization fuel quota for a crate
    -Z                       function-sections=val -- whether each function should go in its own section
    -Z                    future-incompat-test=val -- forces all lints to be future incompatible, used for internal testing (default: no)
    -Z                                  gcc-ld=val -- implementation of ld used by cc
    -Z                      graphviz-dark-mode=val -- use dark-themed colors in graphviz output (default: no)
    -Z                           graphviz-font=val -- use the given `fontname` in graphviz output; can be overridden by setting environment variable `RUSTC_GRAPHVIZ_FONT` (default: `Courier, monospace`)
    -Z                               hir-stats=val -- print some statistics about AST and HIR (default: no)
    -Z                human-readable-cgu-names=val -- generate human-readable, predictable names for codegen units (default: no)
    -Z                        identify-regions=val -- display unnamed regions as `'<id>`, using a non-ident unique id (default: no)
    -Z                incremental-ignore-spans=val -- ignore spans during ICH computation -- used for testing (default: no)
    -Z                        incremental-info=val -- print high-level information about incremental reuse (or the lack thereof) (default: no)
    -Z              incremental-relative-spans=val -- hash spans relative to their parent item for incr. comp. (default: no)
    -Z                  incremental-verify-ich=val -- verify incr. comp. hashes of green query instances (default: no)
    -Z                      inline-in-all-cgus=val -- control whether `#[inline]` functions are in all CGUs
    -Z                             inline-llvm=val -- enable LLVM inlining (default: yes)
    -Z                              inline-mir=val -- enable MIR inlining (default: no)
    -Z               inline-mir-hint-threshold=val -- inlining threshold for functions with inline hint (default: 100)
    -Z                    inline-mir-threshold=val -- a default MIR inlining threshold (default: 50)
    -Z                             input-stats=val -- gather statistics about the input (default: no)
    -Z                     instrument-coverage=val -- instrument the generated code to support LLVM source-based code coverage reports (note, the compiler build config must include `profiler = true`); implies `-C symbol-mangling-version=v0`. Optional values are:
        `=all` (implicit value)
        `=except-unused-generics`
        `=except-unused-functions`
        `=off` (default)
    -Z                       instrument-mcount=val -- insert function instrument code for mcount-based tracing (default: no)
    -Z                       keep-hygiene-data=val -- keep hygiene data after analysis (default: no)
    -Z        layout-random-padding-max-factor=val -- set the maximum field alignment padding multiple when using 'randomize-layout' (default: 3)
    -Z                             layout-seed=val -- seed layout randomization
    -Z                   link-native-libraries=val -- link native libraries in the linker invocation (default: yes)
    -Z                               link-only=val -- link the `.rlink` file generated by `-Z no-link` (default: no)
    -Z                            llvm-plugins=val -- a list LLVM plugins to enable (space separated)
    -Z                         llvm-time-trace=val -- generate JSON tracing data file from LLVM data (default: no)
    -Z                         location-detail=val -- what location details should be tracked when using caller_location, either `none`, or a comma separated list of location details, for which valid options are `file`, `line`, and `column` (default: `file,line,column`)
    -Z                                      ls=val -- list the symbols defined by a library crate (default: no)
    -Z                         macro-backtrace=val -- show macro backtraces (default: no)
    -Z             maximal-hir-to-mir-coverage=val -- save as much information as possible about the correspondence between MIR and HIR as source scopes (default: no)
    -Z                         merge-functions=val -- control the operation of the MergeFunctions LLVM pass, taking the same values as the target option of the same name
    -Z                              meta-stats=val -- gather metadata statistics (default: no)
    -Z                          mir-emit-retag=val -- emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 (default: no)
    -Z                       mir-enable-passes=val -- use like `-Zmir-enable-passes=+DestProp,-InstCombine`. Forces the specified passes to be enabled, overriding all other checks. Passes that are not specified are enabled or disabled by other flags as usual.
    -Z                           mir-opt-level=val -- MIR optimization level (0-4; default: 1 in non optimized builds and 2 in optimized builds)
    -Z        mir-pretty-relative-line-numbers=val -- use line numbers relative to the function in mir pretty printing
    -Z                         move-size-limit=val -- the size at which the `large_assignments` lint starts to be emitted
    -Z                         mutable-noalias=val -- emit noalias metadata for mutable references (default: yes)
    -Z                               nll-facts=val -- dump facts from NLL analysis into side files (default: no)
    -Z                           nll-facts-dir=val -- the directory the NLL facts are dumped into (default: `nll-facts`)
    -Z                             no-analysis=val -- parse and expand the source, but run no analysis
    -Z                              no-codegen=val -- run all passes except codegen; no output
    -Z              no-generate-arange-section=val -- omit DWARF address ranges that give faster lookups
    -Z                           no-leak-check=val -- disable the 'leak check' for subtyping; unsound, but useful for tests
    -Z                                 no-link=val -- compile without linking
    -Z                        no-parallel-llvm=val -- run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)
    -Z                     no-profiler-runtime=val -- prevent automatic injection of the profiler_builtins crate
    -Z                 no-unique-section-names=val -- do not use unique names for text and data sections when -Z function-sections is used
    -Z                          normalize-docs=val -- normalize associated items in rustdoc when generating documentation
    -Z                                     oom=val -- panic strategy for out-of-memory handling
    -Z                  osx-rpath-install-name=val -- pass `-install_name @rpath/...` to the macOS linker (default: no)
    -Z                     packed-bundled-libs=val -- change rlib format to store native libraries as archives
    -Z                       panic-abort-tests=val -- support compiling tests with panic=abort (default: no)
    -Z                           panic-in-drop=val -- panic strategy for panics in drops
    -Z                              parse-only=val -- parse only; do not compile, assemble, or link (default: no)
    -Z                              perf-stats=val -- print some performance-related statistics (default: no)
    -Z pick-stable-methods-before-any-unstable=val -- try to pick stable methods first before picking any unstable methods (default: yes)
    -Z                                     plt=val -- whether to use the PLT when calling into shared libraries;
        only has effect for PIC code on systems with ELF binaries
        (default: PLT is disabled if full relro is enabled)
    -Z                                polonius=val -- enable polonius-based borrow-checker (default: no)
    -Z                            polymorphize=val -- perform polymorphization analysis
    -Z                            pre-link-arg=val -- a single extra argument to prepend the linker invocation (can be used several times)
    -Z                           pre-link-args=val -- extra arguments to prepend to the linker invocation (space separated)
    -Z           precise-enum-drop-elaboration=val -- use a more precise version of drop elaboration for matches on enums (default: yes). This results in better codegen, but has caused miscompilations on some tier 2 platforms. See #77382 and #74551.
    -Z                              print-fuel=val -- make rustc print the total optimization fuel used by a crate
    -Z                       print-llvm-passes=val -- print the LLVM optimization passes being run (default: no)
    -Z                        print-mono-items=val -- print the result of the monomorphization collection pass
    -Z                        print-type-sizes=val -- print layout information for each type encountered (default: no)
    -Z                    proc-macro-backtrace=val -- show backtraces for panics during proc-macro execution (default: no)
    -Z           proc-macro-execution-strategy=val -- how to run proc-macro code (default: same-thread)
    -Z                                 profile=val -- insert profiling code (default: no)
    -Z                        profile-closures=val -- profile size of closures
    -Z                            profile-emit=val -- file path to emit profiling data at runtime when using 'profile' (default based on relative source path)
    -Z                      profile-sample-use=val -- use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)
    -Z                        profiler-runtime=val -- name of the profiler runtime crate to automatically inject (default: `profiler_builtins`)
    -Z                         query-dep-graph=val -- enable queries of the dependency graph for regression testing (default: no)
    -Z                        randomize-layout=val -- randomize the layout of types (default: no)
    -Z                   relax-elf-relocations=val -- whether ELF relocations can be relaxed
    -Z                             relro-level=val -- choose which RELRO level to use
    -Z                        remap-cwd-prefix=val -- remap paths under the current working directory to this path prefix
    -Z                     report-delayed-bugs=val -- immediately print bugs registered with `delay_span_bug` (default: no)
    -Z                               sanitizer=val -- use a sanitizer
    -Z          sanitizer-memory-track-origins=val -- enable origins tracking in MemorySanitizer
    -Z                       sanitizer-recover=val -- enable recovery for selected sanitizers
    -Z                  saturating-float-casts=val -- make float->int casts UB-free: numbers outside the integer type's range are clipped to the max/min integer respectively, and NaN is mapped to 0 (default: yes)
    -Z                           save-analysis=val -- write syntax and type analysis (in JSON format) information, in addition to normal output (default: no)
    -Z                            self-profile=val -- run the self profiler and output the raw event data
    -Z                    self-profile-counter=val -- counter used by the self profiler (default: `wall-time`), one of:
        `wall-time` (monotonic clock, i.e. `std::time::Instant`)
        `instructions:u` (retired instructions, userspace-only)
        `instructions-minus-irqs:u` (subtracting hardware interrupt counts for extra accuracy)
    -Z                     self-profile-events=val -- specify the events recorded by the self profiler;
        for example: `-Z self-profile-events=default,query-keys`
        all options: none, all, default, generic-activity, query-provider, query-cache-hit
                     query-blocked, incr-cache-load, incr-result-hashing, query-keys, function-args, args, llvm, artifact-sizes
    -Z                          share-generics=val -- make the current crate share its generic instantiations
    -Z                               show-span=val -- show spans for compiler debugging (expr|pat|ty)
    -Z         simulate-remapped-rust-src-base=val -- simulate the effect of remap-debuginfo = true at bootstrapping by remapping path to rust's source base directory. only meant for testing purposes
    -Z                              span-debug=val -- forward proc_macro::Span's `Debug` impl to `Span`
    -Z                       span-free-formats=val -- exclude spans when debug-printing compiler state (default: no)
    -Z                    split-dwarf-inlining=val -- provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF
    -Z                        split-dwarf-kind=val -- split dwarf variant (only if -Csplit-debuginfo is enabled and on relevant platform)
        (default: `split`)

        `split`: sections which do not require relocation are written into a DWARF object (`.dwo`)
                 file which is ignored by the linker
        `single`: sections which do not require relocation are written into object file but ignored
                  by the linker
    -Z                      src-hash-algorithm=val -- hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)
    -Z                         stack-protector=val -- control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)
    -Z                      strict-init-checks=val -- control if mem::uninitialized and mem::zeroed panic on more UB
    -Z                                   strip=val -- tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)
    -Z                 symbol-mangling-version=val -- which mangling version to use for symbol names ('legacy' (default) or 'v0')
    -Z                                   teach=val -- show extended diagnostic help (default: no)
    -Z                               temps-dir=val -- the directory the intermediate files are written to
    -Z                                 thinlto=val -- enable ThinLTO when possible
    -Z                           thir-unsafeck=val -- use the THIR unsafety checker (default: no)
    -Z                                 threads=val -- use a thread pool with N threads
    -Z                        time-llvm-passes=val -- measure time of each LLVM pass (default: no)
    -Z                             time-passes=val -- measure time of each rustc pass (default: no)
    -Z                               tls-model=val -- choose the TLS model to use (`rustc --print tls-models` for details)
    -Z                            trace-macros=val -- for every macro invocation, print its name and arguments (default: no)
    -Z                       track-diagnostics=val -- tracks where in rustc a diagnostic was emitted
    -Z                translate-additional-ftl=val -- additional fluent translation to preferentially use (for testing translation)
    -Z        translate-directionality-markers=val -- emit directionality isolation markers in translated diagnostics
    -Z                          translate-lang=val -- language identifier for diagnostic output
    -Z   translate-remapped-path-to-local-path=val -- translate remapped paths into local paths when possible (default: yes)
    -Z                        trap-unreachable=val -- generate trap instructions for unreachable intrinsics (default: use target setting, usually yes)
    -Z                        treat-err-as-bug=val -- treat error number `val` that occurs as bug
    -Z                   trim-diagnostic-paths=val -- in diagnostics, use heuristics to shorten paths referring to items
    -Z                                tune-cpu=val -- select processor to schedule for (`rustc --print target-cpus` for details)
    -Z                              ui-testing=val -- emit compiler diagnostics in a form suitable for UI testing (default: no)
    -Z            uninit-const-chunk-threshold=val -- allow generating const initializers with mixed init/uninit chunks, and set the maximum number of chunks for which this is allowed (default: 16)
    -Z          unleash-the-miri-inside-of-you=val -- take the brakes off const evaluation. NOTE: this is unsound (default: no)
    -Z                                unpretty=val -- present the input source, unstable (and less-pretty) variants;
        `normal`, `identified`,
        `expanded`, `expanded,identified`,
        `expanded,hygiene` (with internal representations),
        `ast-tree` (raw AST before expansion),
        `ast-tree,expanded` (raw AST after expansion),
        `hir` (the HIR), `hir,identified`,
        `hir,typed` (HIR with types for each node),
        `hir-tree` (dump the raw HIR),
        `mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)
    -Z                        unsound-mir-opts=val -- enable unsound and buggy MIR optimizations (default: no)
    -Z                        unstable-options=val -- adds unstable command line options to rustc interface (default: no)
    -Z                       use-ctors-section=val -- use legacy .ctors section for initializers rather than .init_array
    -Z                            validate-mir=val -- validate MIR after each transformation
    -Z                                 verbose=val -- in general, enable more debug printouts (default: no)
    -Z                          verify-llvm-ir=val -- verify LLVM IR (default: no)
    -Z            virtual-function-elimination=val -- enables dead virtual function elimination optimization. Requires `-Clto[=[fat,yes]]`
    -Z                         wasi-exec-model=val -- whether to build a wasi command or reactor
stderr: none



@albertlarsan68

This comment was marked as off-topic.

@rustbot rustbot removed the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Jan 18, 2023
@workingjubilee workingjubilee added the -Zrandomize-layout Unstable option: Randomize the layout of types. label Mar 5, 2023
@Dylan-DPC
Copy link
Member

@Kixiron any updates on this?

@Dylan-DPC
Copy link
Member

Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks

@Dylan-DPC Dylan-DPC closed this Feb 3, 2024
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 3, 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. S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.