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

should be implemented in ISLE: inst = v12 = smulhi.i8 v0, v0, type = Some(types::I8) #1455

Open
cbeuw opened this issue Feb 3, 2024 · 10 comments
Labels
C-bug Category: This is a bug. O-x86_64 Target: x64 processors upstream Caused by a dependency

Comments

@cbeuw
Copy link
Contributor

cbeuw commented Feb 3, 2024

Reproduction is in Custom MIR. Not sure if this can be triggered from surface rust

#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;

#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn13(mut _7: i8) {
    mir! {
    let _25: i16;
    let _31: (i128, i16);
    let _39: i16;
    {
    _31.1 = _7 as i16;
    _25 = _31.1 * _31.1;
    _31 = (50414009528881047150422352225052180952_i128, _25);
    _25 = _31.1 >> _31.0;
    Goto(bb17)
    }
    bb17 = {
    Call(_39 = std::hint::black_box(_25), ReturnTo(bb18), UnwindUnreachable())
    }
    bb18 = {
    Return()
    }

    }
}
pub fn main() {
    fn13(0);
}
$ rustc-clif -Zmir-opt-level=0 -Copt-level=3 929244-debug.rs
thread '<unnamed>' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cranelift-codegen-0.104.0/src/machinst/lower.rs:766:21:
should be implemented in ISLE: inst = `v12 = smulhi.i8 v0, v0`, type = `Some(types::I8)`
stack backtrace:
   0:     0x7ffff978bf86 - std::backtrace_rs::backtrace::libunwind::trace::h514ead2753e1782f
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7ffff978bf86 - std::backtrace_rs::backtrace::trace_unsynchronized::hbc462e8372651887
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ffff978bf86 - std::sys_common::backtrace::_print_fmt::he3092ef183bdd613
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ffff978bf86 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h908f80a389799910
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ffff97de880 - core::fmt::rt::Argument::fmt::ha9f3d8b02e25296c
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/core/src/fmt/rt.rs:142:9
   5:     0x7ffff97de880 - core::fmt::write::hef880bc86bd63d4b
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/core/src/fmt/mod.rs:1120:17
   6:     0x7ffff977f94f - std::io::Write::write_fmt::h780869503f755b5a
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/io/mod.rs:1810:15
   7:     0x7ffff978bd64 - std::sys_common::backtrace::_print::h52cc78326ec17ac5
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ffff978bd64 - std::sys_common::backtrace::print::h44b4c057fd1c7c3f
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ffff978eaf7 - std::panicking::default_hook::{{closure}}::h99cbf699c09f8685
  10:     0x7ffff978e859 - std::panicking::default_hook::hbc89d54398681576
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:292:9
  11:     0x7ffffc54acec - std[1d0ea5b5e602c844]::panicking::update_hook::<alloc[d84df3010862da1b]::boxed::Box<rustc_driver_impl[2078f68ece4ea2b8]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ffff978f246 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h99950b3f8a1ddee8
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/alloc/src/boxed.rs:2029:9
  13:     0x7ffff978f246 - std::panicking::rust_panic_with_hook::he160495ec53b11e6
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:785:13
  14:     0x7ffff978ef92 - std::panicking::begin_panic_handler::{{closure}}::ha86f6320ad4cac49
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:659:13
  15:     0x7ffff978c486 - std::sys_common::backtrace::__rust_end_short_backtrace::h19c3911246e5b7ea
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7ffff978ece4 - rust_begin_unwind
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/panicking.rs:647:5
  17:     0x7ffff97daf85 - core::panicking::panic_fmt::hd869deda4756f0c1
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/core/src/panicking.rs:72:14
  18:     0x7ffff06f38f8 - cranelift_codegen::machinst::lower::Lower<I>::lower::hf5680db6e8da6825
  19:     0x7ffff05d6739 - cranelift_codegen::machinst::compile::compile::h5311fd7207db3d5c
  20:     0x7ffff06936f5 - <cranelift_codegen::isa::x64::X64Backend as cranelift_codegen::isa::TargetIsa>::compile_function::h590f11e5c6d2c4ff
  21:     0x7ffff0709f5b - cranelift_codegen::context::Context::compile_stencil::h96dc3cd783467e94
  22:     0x7ffff0709c37 - cranelift_codegen::context::Context::compile_and_emit::h593fc7e7957fe7fc
  23:     0x7ffff0499eca - <cranelift_object::backend::ObjectModule as cranelift_module::module::Module>::define_function_with_control_plane::hc9ac75d45c4de148
  24:     0x7ffff03e4ec3 - cranelift_module::module::Module::define_function::hb378a4ac6a6da2a5
  25:     0x7ffff046fd8d - rustc_codegen_cranelift::base::compile_fn::he5118887952ffc76
  26:     0x7ffff042c8ab - std::sys_common::backtrace::__rust_begin_short_backtrace::h37b57af66c3e318c
  27:     0x7ffff0429604 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hb385e8dc4fe3342d
  28:     0x7ffff9798835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hba0b80fd74ce5417
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/alloc/src/boxed.rs:2015:9
  29:     0x7ffff9798835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0ab2d213dcdff51c
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/alloc/src/boxed.rs:2015:9
  30:     0x7ffff9798835 - std::sys::pal::unix::thread::Thread::new::thread_start::h7eeca5a8e186b7ad
                               at /rustc/e7bbe8ce933123a8e327c79e38bcb790595e6a65/library/std/src/sys/pal/unix/thread.rs:108:17
  31:     0x7ffff9586897 - start_thread
  32:     0x7ffff960d564 - __GI___clone
  33:                0x0 - <unknown>

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

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `/root/rustlantis-repros/rustc-ice-2024-02-03T11_40_43-99834.txt` to your bug report

note: compiler flags: -C panic=abort -Z panic-abort-tests -Z codegen-backend=/root/rustc_codegen_cranelift/dist/lib/librustc_codegen_cranelift.so -Z mir-opt-level=0 -C opt-level=3

query stack during panic:
end of query stack
warning: 2 warnings emitted

On latest cdae185

@bjorn3
Copy link
Member

bjorn3 commented Feb 3, 2024

It looks like you are multiplying a 128bit integer with a 16bit integer. I don't think that is possible in surface rust. Probably something the MIR verifier should be made to deny.

@cbeuw
Copy link
Contributor Author

cbeuw commented Feb 3, 2024

By multiplying I assume you meant shift right?

Shr in MIR is documented with "The offset is truncated to the size of the first operand and made unsigned before shifting."

This surface Rust also triggers the same panic (though it has UB):

#![allow(arithmetic_overflow)]

pub fn fn13(mut _7:i8) {
    let mut _31: (i128, i16) = (0,0);
    let mut _25: i16 = 0;
    let mut _39: i16 = 0;
    _31.1 = _7 as i16;
    _25 = _31.1 * _31.1;
    _31 = (50414009528881047150422352225052180952_i128, _25);
    _25 = _31.1 >> _31.0 as u128;
    std::hint::black_box(_25);
}

pub fn main() {
    fn13(0);
}

@bjorn3
Copy link
Member

bjorn3 commented Feb 3, 2024

I misread the _25 = _31.1 * _31.1; (i16 times itself) as _25 = _31.0 * _31.1; (i128 times i16).

The only place where cg_clif emits an smulhi is when multiplying with the left hand side being a 128bit integer:

let val_hi = fx.bcx.ins().smulhi(lhs, rhs);

This surface Rust also triggers the same panic (though it has UB):

I see. It doesn't have UB by the way. There is no unsafe code. Shifting with overflow is defined as panicking at runtime. The lint you suppressed only triggers when rustc knows the shift amount at compile time already.

In any case I can't reproduce this error on aarch64-unknown-linux-gnu, but I can reproduce it on x86_64-unknown-linux-gnu. It seems to be a Cranelift issue. I reduced it to:

test compile
set opt_level=speed
target x86_64

function u0:9(i8) -> i16 system_v {
block0(v0: i8):
    v8 = sextend.i16 v0
    v9 = imul v8, v8
    v10 = iconst.i64 1000
    v13 = sshr v9, v10  ; v10 = 1000
    return v13
}

@bjorn3
Copy link
Member

bjorn3 commented Feb 3, 2024

I've reported this upstream at bytecodealliance/wasmtime#7865. Thanks for reporting this to me!

@matthiaskrgr
Copy link
Member

I've found something similar involving simd stuff, might be related:

auto-reduced (treereduce-rust):

#![crate_type = "lib"]
#![feature(repr_simd, platform_intrinsics)]

#[repr(simd)]

pub struct f32x2(pub f32, pub f32);

extern "platform-intrinsic" {
    fn simd_fcos<T>(x: T) -> T;
}

pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
    simd_fcos(a)
}
original code

original:

// compile-flags: -C no-prepopulate-passes

#![crate_type = "lib"]

#![feature(repr_simd, platform_intrinsics)]
#![allow(non_camel_case_types)]

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x2(pub f32, pub f32);

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x8(pub f32, pub f32, pub f32, pub f32,
                 pub f32, pub f32, pub f32, pub f32);

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f32x16(pub f32, pub f32, pub f32, pub f32,
                  pub f32, pub f32, pub f32, pub f32,
                  pub f32, pub f32, pub f32, pub f32,
                  pub f32, pub f32, pub f32, pub f32);

extern "platform-intrinsic" {
    fn simd_fcos<T>(x: T) -> T;
}

// CHECK-LABEL: @fcos_32x2
#[no_mangle]
pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
    // CHECK: call <2 x float> @llvm.cos.v2f32
    simd_fcos(a)
}

// CHECK-LABEL: @fcos_32x4
#[no_mangle]
pub unsafe fn fcos_32x4(a: f32x4) -> f32x4 {
    // CHECK: call <4 x float> @llvm.cos.v4f32
    simd_fcos(a)
}

// CHECK-LABEL: @fcos_32x8
#[no_mangle]
pub unsafe fn fcos_32x8(a: f32x8) -> f32x8 {
    // CHECK: call <8 x float> @llvm.cos.v8f32
    simd_fcos(a)
}

// CHECK-LABEL: @fcos_32x16
#[no_mangle]
pub unsafe fn fcos_32x16(a: f32x16) -> f32x16 {
    // CHECK: call <16 x float> @llvm.cos.v16f32
    simd_fcos(a)
}

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f64x2(pub f64, pub f64);

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f64x4(pub f64, pub f64, pub f64, pub f64);

#[repr(simd)]
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct f64x8(pub f64, pub f64, pub f64, pub f64,
                 pub f64, pub f64, pub f64, pub f64);

// CHECK-LABEL: @fcos_64x4
#[no_mangle]
pub unsafe fn fcos_64x4(a: f64x4) -> f64x4 {
    // CHECK: call <4 x double> @llvm.cos.v4f64
    simd_fcos(a)
}

// CHECK-LABEL: @fcos_64x2
#[no_mangle]
pub unsafe fn fcos_64x2(a: f64x2) -> f64x2 {
    // CHECK: call <2 x double> @llvm.cos.v2f64
    simd_fcos(a)
}

// CHECK-LABEL: @fcos_64x8
#[no_mangle]
pub unsafe fn fcos_64x8(a: f64x8) -> f64x8 {
    // CHECK: call <8 x double> @llvm.cos.v8f64
    simd_fcos(a)
}

Version information

rustc 1.78.0-nightly (bdc15928c 2024-02-12)
binary: rustc
commit-hash: bdc15928c8119a86d15e2946cb54851264607842
commit-date: 2024-02-12
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcodegen-backend=cranelift

Program output

warning: the feature `platform_intrinsics` is internal to the compiler or standard library
 --> /tmp/icemaker_global_tempdir.invhaiigiPnt/rustc_testrunner_tmpdir_reporting.y089HvaBptEQ/mvce.rs:2:23
  |
2 | #![feature(repr_simd, platform_intrinsics)]
  |                       ^^^^^^^^^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: type `f32x2` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.invhaiigiPnt/rustc_testrunner_tmpdir_reporting.y089HvaBptEQ/mvce.rs:6:12
  |
6 | pub struct f32x2(pub f32, pub f32);
  |            ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `F32x2`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: `extern` fn uses type `f32x2`, which is not FFI-safe
  --> /tmp/icemaker_global_tempdir.invhaiigiPnt/rustc_testrunner_tmpdir_reporting.y089HvaBptEQ/mvce.rs:12:46
   |
12 | pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
   |                                              ^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> /tmp/icemaker_global_tempdir.invhaiigiPnt/rustc_testrunner_tmpdir_reporting.y089HvaBptEQ/mvce.rs:6:1
   |
6  | pub struct f32x2(pub f32, pub f32);
   | ^^^^^^^^^^^^^^^^
   = note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `f32x2`, which is not FFI-safe
  --> /tmp/icemaker_global_tempdir.invhaiigiPnt/rustc_testrunner_tmpdir_reporting.y089HvaBptEQ/mvce.rs:12:56
   |
12 | pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
   |                                                        ^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> /tmp/icemaker_global_tempdir.invhaiigiPnt/rustc_testrunner_tmpdir_reporting.y089HvaBptEQ/mvce.rs:6:1
   |
6  | pub struct f32x2(pub f32, pub f32);
   | ^^^^^^^^^^^^^^^^

thread '<unnamed>' panicked at /rust/deps/cranelift-codegen-0.104.0/src/machinst/lower.rs:766:21:
should be implemented in ISLE: inst = `v5 = load.f32x2 notrap v11`, type = `Some(types::F32X2)`
stack backtrace:
   0:     0x7feea818a476 - std::backtrace_rs::backtrace::libunwind::trace::h8ef947617e16f822
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7feea818a476 - std::backtrace_rs::backtrace::trace_unsynchronized::hb66b057a427083f0
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7feea818a476 - std::sys_common::backtrace::_print_fmt::ha10750ee1dc54ed0
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7feea818a476 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb6d0154de076c6e6
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7feea81dd030 - core::fmt::rt::Argument::fmt::he4c314755b9e6afc
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/core/src/fmt/rt.rs:142:9
   5:     0x7feea81dd030 - core::fmt::write::hb3e06633f499afa7
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/core/src/fmt/mod.rs:1120:17
   6:     0x7feea817dcff - std::io::Write::write_fmt::hc994b08725869490
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/io/mod.rs:1854:15
   7:     0x7feea818a254 - std::sys_common::backtrace::_print::h42a654a316d75708
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7feea818a254 - std::sys_common::backtrace::print::hca51ca528a9e0f01
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7feea818d047 - std::panicking::default_hook::{{closure}}::hb09261a73b1ed161
  10:     0x7feea818cda9 - std::panicking::default_hook::h1f48eb560843ebc7
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/panicking.rs:292:9
  11:     0x7feeaaf5ba0c - std[75f6d10604fe8718]::panicking::update_hook::<alloc[6c2a3573fcbdf6f8]::boxed::Box<rustc_driver_impl[36e65a358b47fd1a]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7feea818d796 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hde685e838b43f292
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/alloc/src/boxed.rs:2030:9
  13:     0x7feea818d796 - std::panicking::rust_panic_with_hook::h3c97de3356735f38
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/panicking.rs:785:13
  14:     0x7feea818d4e2 - std::panicking::begin_panic_handler::{{closure}}::hafdfc04176a4e9ff
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/panicking.rs:659:13
  15:     0x7feea818a976 - std::sys_common::backtrace::__rust_end_short_backtrace::hc040a4b909424ea0
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7feea818d234 - rust_begin_unwind
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/panicking.rs:647:5
  17:     0x7feea81d9785 - core::panicking::panic_fmt::h84058fea44ddb2f4
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/core/src/panicking.rs:72:14
  18:     0x7fee9e95dde8 - <cranelift_codegen[fdc42ee38c36a071]::machinst::lower::Lower<cranelift_codegen[fdc42ee38c36a071]::isa::x64::lower::isle::generated_code::MInst>>::lower::<cranelift_codegen[fdc42ee38c36a071]::isa::x64::X64Backend>
  19:     0x7fee9e9959e6 - cranelift_codegen[fdc42ee38c36a071]::machinst::compile::compile::<cranelift_codegen[fdc42ee38c36a071]::isa::x64::X64Backend>
  20:     0x7fee9ea476cf - <cranelift_codegen[fdc42ee38c36a071]::isa::x64::X64Backend as cranelift_codegen[fdc42ee38c36a071]::isa::TargetIsa>::compile_function
  21:     0x7fee9ead478d - <cranelift_codegen[fdc42ee38c36a071]::context::Context>::compile_stencil
  22:     0x7fee9ead4487 - <cranelift_codegen[fdc42ee38c36a071]::context::Context>::compile_and_emit
  23:     0x7fee9e86eb67 - <cranelift_object[7f3da09581662714]::backend::ObjectModule as cranelift_module[1585b68559fd3688]::module::Module>::define_function_with_control_plane
  24:     0x7fee9e8281ed - rustc_codegen_cranelift[499aaa9d066c9c53]::driver::aot::module_codegen::{closure#1}
  25:     0x7fee9e7c6556 - std[75f6d10604fe8718]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_codegen_cranelift[499aaa9d066c9c53]::driver::aot::module_codegen::{closure#1}, core[dbbaaa7a4ecd5b73]::result::Result<rustc_codegen_cranelift[499aaa9d066c9c53]::driver::aot::ModuleCodegenResult, alloc[6c2a3573fcbdf6f8]::string::String>>
  26:     0x7fee9e7d48b5 - <<std[75f6d10604fe8718]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[499aaa9d066c9c53]::driver::aot::module_codegen::{closure#1}, core[dbbaaa7a4ecd5b73]::result::Result<rustc_codegen_cranelift[499aaa9d066c9c53]::driver::aot::ModuleCodegenResult, alloc[6c2a3573fcbdf6f8]::string::String>>::{closure#1} as core[dbbaaa7a4ecd5b73]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7feea8196985 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd2ae1cd961e27068
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/alloc/src/boxed.rs:2016:9
  28:     0x7feea8196985 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h44d13c09fd0d253c
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/alloc/src/boxed.rs:2016:9
  29:     0x7feea8196985 - std::sys::pal::unix::thread::Thread::new::thread_start::habbab97a1fb1aa1d
                               at /rustc/bdc15928c8119a86d15e2946cb54851264607842/library/std/src/sys/pal/unix/thread.rs:108:17
  30:     0x7feea7f4a9eb - <unknown>
  31:     0x7feea7fce7cc - <unknown>
  32:                0x0 - <unknown>

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

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: rustc 1.78.0-nightly (bdc15928c 2024-02-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z codegen-backend=cranelift -Z dump-mir-dir=dir

query stack during panic:
end of query stack
warning: 4 warnings emitted


@bjorn3
Copy link
Member

bjorn3 commented Mar 9, 2024

The multiplication issue has been fixed.

@matthiaskrgr I can't reproduce your crash. I had to change it to

#![crate_type = "lib"]
#![feature(repr_simd, intrinsics)]

#[repr(simd)]

pub struct f32x2(pub f32, pub f32);

extern "rust-intrinsic" {
    fn simd_fcos<T>(x: T) -> T;
}

pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
    simd_fcos(a)
}

as extern "platform-intrinsics" is now gone.

@matthiaskrgr
Copy link
Member

is this an x86 thing again? 😅

with #1455 (comment)

rustc 1.78.0-nightly (46b180ec2 2024-03-08)
binary: rustc
commit-hash: 46b180ec2452d388c5d9c14009442e2e0beb01d7
commit-date: 2024-03-08
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

rustc a.rs -Zcodegen-backend=cranelift

warning: the feature `intrinsics` is internal to the compiler or standard library
 --> a.rs:2:23
  |
2 | #![feature(repr_simd, intrinsics)]
  |                       ^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

warning: type `f32x2` should have an upper camel case name
 --> a.rs:6:12
  |
6 | pub struct f32x2(pub f32, pub f32);
  |            ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `F32x2`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: `extern` fn uses type `f32x2`, which is not FFI-safe
  --> a.rs:12:46
   |
12 | pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
   |                                              ^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> a.rs:6:1
   |
6  | pub struct f32x2(pub f32, pub f32);
   | ^^^^^^^^^^^^^^^^
   = note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `f32x2`, which is not FFI-safe
  --> a.rs:12:56
   |
12 | pub unsafe extern "C-unwind" fn fcos_32x2(a: f32x2) -> f32x2 {
   |                                                        ^^^^^ not FFI-safe
   |
   = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
   = note: this struct has unspecified layout
note: the type is defined here
  --> a.rs:6:1
   |
6  | pub struct f32x2(pub f32, pub f32);
   | ^^^^^^^^^^^^^^^^

thread '<unnamed>' panicked at /rust/deps/cranelift-codegen-0.104.0/src/machinst/lower.rs:766:21:
should be implemented in ISLE: inst = `v5 = load.f32x2 notrap v11`, type = `Some(types::F32X2)`
stack backtrace:
   0:     0x7f213d78ca52 - std::backtrace_rs::backtrace::libunwind::trace::h28d52d4a76871913
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f213d78ca52 - std::backtrace_rs::backtrace::trace_unsynchronized::h503ea3de55b2f93a
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f213d78ca52 - std::sys_common::backtrace::_print_fmt::h7c876b0271ead112
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f213d78ca52 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf5aadce27155ac5d
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f213d7dda5c - core::fmt::rt::Argument::fmt::h13d90bf5fbe267cf
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/core/src/fmt/rt.rs:142:9
   5:     0x7f213d7dda5c - core::fmt::write::h2de89e906ae130f8
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/core/src/fmt/mod.rs:1153:17
   6:     0x7f213d78155f - std::io::Write::write_fmt::h474fe2851308390a
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/io/mod.rs:1846:15
   7:     0x7f213d78c824 - std::sys_common::backtrace::_print::h71e1c5fa8a76cc1f
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f213d78c824 - std::sys_common::backtrace::print::h6de4bd76b46f8a90
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f213d78f52b - std::panicking::default_hook::{{closure}}::hf548fd40a9216b9d
  10:     0x7f213d78f287 - std::panicking::default_hook::hce3f5ab890486de1
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/panicking.rs:292:9
  11:     0x7f21406593bc - std[40371b03452e9629]::panicking::update_hook::<alloc[1c695e7685c40be4]::boxed::Box<rustc_driver_impl[e020cafba1d663ef]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f213d78fc90 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3f8fec9da151cd79
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/alloc/src/boxed.rs:2030:9
  13:     0x7f213d78fc90 - std::panicking::rust_panic_with_hook::h4cae9e0f3cf6214b
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/panicking.rs:783:13
  14:     0x7f213d78f9d2 - std::panicking::begin_panic_handler::{{closure}}::h3d1abdf9392922f6
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/panicking.rs:657:13
  15:     0x7f213d78cf26 - std::sys_common::backtrace::__rust_end_short_backtrace::h68b8a42a6ea5942d
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f213d78f704 - rust_begin_unwind
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/panicking.rs:645:5
  17:     0x7f213d7d9f75 - core::panicking::panic_fmt::he5f6ace403ad1db0
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/core/src/panicking.rs:72:14
  18:     0x7f213415225d - <cranelift_codegen[a09255f40a5caa31]::machinst::lower::Lower<cranelift_codegen[a09255f40a5caa31]::isa::x64::lower::isle::generated_code::MInst>>::lower::<cranelift_codegen[a09255f40a5caa31]::isa::x64::X64Backend>
  19:     0x7f213418c27b - cranelift_codegen[a09255f40a5caa31]::machinst::compile::compile::<cranelift_codegen[a09255f40a5caa31]::isa::x64::X64Backend>
  20:     0x7f2134215199 - <cranelift_codegen[a09255f40a5caa31]::isa::x64::X64Backend as cranelift_codegen[a09255f40a5caa31]::isa::TargetIsa>::compile_function
  21:     0x7f2134299c47 - <cranelift_codegen[a09255f40a5caa31]::context::Context>::compile_stencil
  22:     0x7f2134299947 - <cranelift_codegen[a09255f40a5caa31]::context::Context>::compile_and_emit
  23:     0x7f213406b751 - <cranelift_object[b63c4d02444cd865]::backend::ObjectModule as cranelift_module[4d4182e78a0bce0]::module::Module>::define_function_with_control_plane
  24:     0x7f21340262bd - rustc_codegen_cranelift[e89abcfa756346c6]::driver::aot::module_codegen::{closure#1}
  25:     0x7f2133fc3946 - std[40371b03452e9629]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_codegen_cranelift[e89abcfa756346c6]::driver::aot::module_codegen::{closure#1}, core[94452985e868f073]::result::Result<rustc_codegen_cranelift[e89abcfa756346c6]::driver::aot::ModuleCodegenResult, alloc[1c695e7685c40be4]::string::String>>
  26:     0x7f2133fd1bc4 - <<std[40371b03452e9629]::thread::Builder>::spawn_unchecked_<rustc_codegen_cranelift[e89abcfa756346c6]::driver::aot::module_codegen::{closure#1}, core[94452985e868f073]::result::Result<rustc_codegen_cranelift[e89abcfa756346c6]::driver::aot::ModuleCodegenResult, alloc[1c695e7685c40be4]::string::String>>::{closure#1} as core[94452985e868f073]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x7f213d799435 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9aa150da2b8878a0
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/alloc/src/boxed.rs:2016:9
  28:     0x7f213d799435 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9e33e08a039d33be
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/alloc/src/boxed.rs:2016:9
  29:     0x7f213d799435 - std::sys::pal::unix::thread::Thread::new::thread_start::h15066c44878d31b1
                               at /rustc/46b180ec2452d388c5d9c14009442e2e0beb01d7/library/std/src/sys/pal/unix/thread.rs:108:17
  30:     0x7f213d58155a - <unknown>
  31:     0x7f213d5fea3c - <unknown>
  32:                0x0 - <unknown>

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

note: using internal features is not supported and expected to cause internal compiler errors when used incorrectly

note: please attach the file at `/tmp/im/rustc-ice-2024-03-09T17_53_46-2793847.txt` to your bug report

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

query stack during panic:
end of query stack
warning: 4 warnings emitted

@bjorn3
Copy link
Member

bjorn3 commented Mar 9, 2024

Yes, it reproduces on x86_64.

@bjorn3
Copy link
Member

bjorn3 commented Mar 9, 2024

I'm not sure if f32x2 is allowed at all by the x86_64 systemv calling convention. It is on aarch64 though (float32x2_t in arm_neon.h for C).

@bjorn3
Copy link
Member

bjorn3 commented Mar 9, 2024

In any case I opened bytecodealliance/wasmtime#8075 to suggest adding load.f32x2 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-x86_64 Target: x64 processors upstream Caused by a dependency
Projects
None yet
Development

No branches or pull requests

3 participants