rust-lang / rustc_codegen_cranelift

Cranelift based backend for rustc
Apache License 2.0
1.52k stars 94 forks source link

Better simd platform intrinsic validation #1328

Open bjorn3 opened 1 year ago

bjorn3 commented 1 year ago

We currently crash on many misuses of the simd platform intrinsics.

matthiaskrgr commented 1 year ago
#![crate_type = "lib"]
#![feature(repr_simd)]

#[derive(Copy, Clone)]
pub enum Unhab {}

#[repr(simd)]
#[derive(Copy, Clone)]
pub struct i64x4(i64, i64, i64, i64);

pub union UnionI64x4_ {
    a: i64x4,
    b: (),
    c: i64x4,
    d: Unhab,
    e: ((), ()),
}

pub extern "C" fn test_UnionI64x4_() -> UnionI64x4_ {
    loop {}
}

#[repr(C)]
pub union CUnionU128 {
    a: u128,
}
thread '<unnamed>' panicked at 'assertion failed: ty.bits() <= 128', /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/isa/x64/inst/mod.rs:2490:17
stack backtrace:
   0:     0x7ff2bc10abf6 - std::backtrace_rs::backtrace::libunwind::trace::h74804ffdd8fa53e7
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff2bc10abf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h7428ab2b67b36e0c
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff2bc10abf6 - std::sys_common::backtrace::_print_fmt::h8de225fa5d864a16
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7ff2bc10abf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf186862c319ab6b0
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff2bc1af698 - core::fmt::rt::Argument::fmt::h6eb98e918eb80ebd
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/fmt/rt.rs:138:9
   5:     0x7ff2bc1af698 - core::fmt::write::hfa7c5695b2a1784c
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/fmt/mod.rs:1094:21
   6:     0x7ff2bc1151bf - std::io::Write::write_fmt::h8780fc8b700f7b89
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/io/mod.rs:1712:15
   7:     0x7ff2bc10a9f5 - std::sys_common::backtrace::_print::h4ce540e460b36e22
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff2bc10a9f5 - std::sys_common::backtrace::print::h6954c2242c47d1db
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff2bc12bebc - std::panicking::default_hook::{{closure}}::h7efa3c73d7318a2f
  10:     0x7ff2bc12bb92 - std::panicking::default_hook::h478ef42d51f84426
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:288:9
  11:     0x7ff2be9e3dfb - <alloc[32b43e9536c01a3]::boxed::Box<dyn for<'a, 'b> core[c5d5d662f7508502]::ops::function::Fn<(&'a core[c5d5d662f7508502]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[c5d5d662f7508502]::marker::Send + core[c5d5d662f7508502]::marker::Sync> as core[c5d5d662f7508502]::ops::function::Fn<(&core[c5d5d662f7508502]::panic::panic_info::PanicInfo,)>>::call
                               at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:1999:9
  12:     0x7ff2be9e3dfb - rustc_driver_impl[73f6269079133b5d]::install_ice_hook::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_driver_impl/src/lib.rs:1258:13
  13:     0x7ff2bc12c75a - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfea6944ca11513b1
                               at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:1999:9
  14:     0x7ff2bc12c75a - std::panicking::rust_panic_with_hook::h3d7c73761f67633f
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:695:13
  15:     0x7ff2bc10baa1 - std::panicking::begin_panic_handler::{{closure}}::h0004dd01860b01c3
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:580:13
  16:     0x7ff2bc10acd6 - std::sys_common::backtrace::__rust_end_short_backtrace::hccbfe31830e0f553
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:150:18
  17:     0x7ff2bc12c2c2 - rust_begin_unwind
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:578:5
  18:     0x7ff2bc1cb363 - core::panicking::panic_fmt::h98b1dd38c1edb68b
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:67:14
  19:     0x7ff2bc1cb3f5 - core::panicking::panic::he5f7c6779e1d5164
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panicking.rs:117:5
  20:     0x7ff2b5a105cd - <cranelift_codegen[e0769f7e8ac42da7]::isa::x64::lower::isle::generated_code::MInst as cranelift_codegen[e0769f7e8ac42da7]::machinst::MachInst>::rc_for_type
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/isa/x64/inst/mod.rs:2490:17
  21:     0x7ff2b5b57f27 - <cranelift_codegen[e0769f7e8ac42da7]::isa::x64::abi::X64ABIMachineSpec as cranelift_codegen[e0769f7e8ac42da7]::machinst::abi::ABIMachineSpec>::compute_arg_locs::<core[c5d5d662f7508502]::iter::adapters::chain::Chain<core[c5d5d662f7508502]::option::IntoIter<&cranelift_codegen[e0769f7e8ac42da7]::ir::extfunc::AbiParam>, core[c5d5d662f7508502]::slice::iter::Iter<cranelift_codegen[e0769f7e8ac42da7]::ir::extfunc::AbiParam>>>
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/isa/x64/abi.rs:126:34
  22:     0x7ff2b5aee0f8 - <cranelift_codegen[e0769f7e8ac42da7]::machinst::abi::SigSet>::from_func_sig::<cranelift_codegen[e0769f7e8ac42da7]::isa::x64::abi::X64ABIMachineSpec>
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/machinst/abi.rs:813:42
  23:     0x7ff2b5aed9f4 - <cranelift_codegen[e0769f7e8ac42da7]::machinst::abi::SigSet>::make_abi_sig_from_ir_signature::<cranelift_codegen[e0769f7e8ac42da7]::isa::x64::abi::X64ABIMachineSpec>
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/machinst/abi.rs:756:24
  24:     0x7ff2b5aeb61a - <cranelift_codegen[e0769f7e8ac42da7]::machinst::abi::SigSet>::new::<cranelift_codegen[e0769f7e8ac42da7]::isa::x64::abi::X64ABIMachineSpec>
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/machinst/abi.rs:725:9
  25:     0x7ff2b5b5b70c - <cranelift_codegen[e0769f7e8ac42da7]::isa::x64::X64Backend>::compile_vcode
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/isa/x64/mod.rs:57:20
  26:     0x7ff2b5b5b70c - <cranelift_codegen[e0769f7e8ac42da7]::isa::x64::X64Backend as cranelift_codegen[e0769f7e8ac42da7]::isa::TargetIsa>::compile_function
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/isa/x64/mod.rs:70:40
  27:     0x7ff2b5ab69ae - <cranelift_codegen[e0769f7e8ac42da7]::context::Context>::compile_stencil
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/context.rs:143:9
  28:     0x7ff2b5ab70ee - <cranelift_codegen[e0769f7e8ac42da7]::context::Context>::compile
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/context.rs:216:23
  29:     0x7ff2b5ab687a - <cranelift_codegen[e0769f7e8ac42da7]::context::Context>::compile_and_emit
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.95.1/src/context.rs:128:29
  30:     0x7ff2b59b2bcf - <cranelift_object[a13f0131eb90437d]::backend::ObjectModule as cranelift_module[735d178e055a412a]::module::Module>::define_function
                               at /home/matthias/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-object-0.95.1/src/backend.rs:326:19
  31:     0x7ff2b58e4998 - rustc_codegen_cranelift[7650e7446ce7893]::base::compile_fn::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_codegen_cranelift/src/base.rs:174:9
  32:     0x7ff2b58e4998 - <rustc_data_structures[bdfdc77573217e6b]::profiling::TimingGuard>::run::<(), rustc_codegen_cranelift[7650e7446ce7893]::base::compile_fn::{closure#0}>
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_data_structures/src/profiling.rs:716:9
  33:     0x7ff2b58e4998 - rustc_codegen_cranelift[7650e7446ce7893]::base::compile_fn
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_codegen_cranelift/src/base.rs:172:53
  34:     0x7ff2b5918d39 - rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_codegen_cranelift/src/driver/aot.rs:333:21
  35:     0x7ff2b5918d39 - <rustc_data_structures[bdfdc77573217e6b]::profiling::VerboseTimingGuard>::run::<(), rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}::{closure#0}>
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_data_structures/src/profiling.rs:752:9
  36:     0x7ff2b5918d39 - rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}
                               at /home/matthias/vcs/github/rust_debug_assertions/compiler/rustc_codegen_cranelift/src/driver/aot.rs:325:96
  37:     0x7ff2b5918d39 - std[68c29493de10bea]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys_common/backtrace.rs:134:18
  38:     0x7ff2b59348e0 - <std[68c29493de10bea]::thread::Builder>::spawn_unchecked_::<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1}::{closure#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/thread/mod.rs:529:17
  39:     0x7ff2b59348e0 - <core[c5d5d662f7508502]::panic::unwind_safe::AssertUnwindSafe<<std[68c29493de10bea]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1}::{closure#0}> as core[c5d5d662f7508502]::ops::function::FnOnce<()>>::call_once
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/panic/unwind_safe.rs:271:9
  40:     0x7ff2b59348e0 - std[68c29493de10bea]::panicking::try::do_call::<core[c5d5d662f7508502]::panic::unwind_safe::AssertUnwindSafe<<std[68c29493de10bea]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1}::{closure#0}>, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:485:40
  41:     0x7ff2b59348e0 - std[68c29493de10bea]::panicking::try::<core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>, core[c5d5d662f7508502]::panic::unwind_safe::AssertUnwindSafe<<std[68c29493de10bea]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1}::{closure#0}>>
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panicking.rs:449:19
  42:     0x7ff2b59348e0 - std[68c29493de10bea]::panic::catch_unwind::<core[c5d5d662f7508502]::panic::unwind_safe::AssertUnwindSafe<<std[68c29493de10bea]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1}::{closure#0}>, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/panic.rs:140:14
  43:     0x7ff2b59348e0 - <std[68c29493de10bea]::thread::Builder>::spawn_unchecked_::<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1}
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/thread/mod.rs:528:30
  44:     0x7ff2b59348e0 - <<std[68c29493de10bea]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::module_codegen::{closure#1}, core[c5d5d662f7508502]::result::Result<rustc_codegen_cranelift[7650e7446ce7893]::driver::aot::ModuleCodegenResult, alloc[32b43e9536c01a3]::string::String>>::{closure#1} as core[c5d5d662f7508502]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
                               at /home/matthias/vcs/github/rust_debug_assertions/library/core/src/ops/function.rs:250:5
  45:     0x7ff2bc11d69a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h59b61553bfddebc8
                               at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:1985:9
  46:     0x7ff2bc11d69a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0ce3d7a7bade6491
                               at /home/matthias/vcs/github/rust_debug_assertions/library/alloc/src/boxed.rs:1985:9
  47:     0x7ff2bc103b15 - std::sys::unix::thread::Thread::new::thread_start::h6e446945f062d041
                               at /home/matthias/vcs/github/rust_debug_assertions/library/std/src/sys/unix/thread.rs:108:17
  48:     0x7ff2bbea6bb5 - <unknown>
  49:     0x7ff2bbf28d90 - <unknown>
  50:                0x0 - <unknown>

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

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

note: rustc 1.71.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z codegen-backend=cranelift

query stack during panic:
end of query stack
warning: 4 warnings emitted
bjorn3 commented 1 year ago

That function uses a 256bit vector type as return value, which requires AVX. Cranelift doesn't yet support AVX.