Skip to content

Internal Compile Error: thread 'rustc' panicked at 'assertion failed: self.appropriate_rvalue_mode(bcx.ccx()) == ByValue', ../src/librustc_trans/datum.rs:789 #33264

Closed
@drrb

Description

@drrb

Updating from a nightly version of rust from 2015-10-13 to one from 2016-04-25 on a medium sized codebase, I get an internal compile error.

Meta

rustc --version --verbose:

rustc 1.10.0-nightly (bd938166d 2016-04-25)
binary: rustc
commit-hash: bd938166d6dabc689777555d5046dce893555eb7
commit-date: 2016-04-25
host: x86_64-apple-darwin
release: 1.10.0-nightly

Backtrace:

error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: self.appropriate_rvalue_mode(bcx.ccx()) == ByValue', ../src/librustc_trans/datum.rs:789
stack backtrace:
   1:        0x10e39eba8 - std::sys::backtrace::tracing::imp::write::h9fb600083204ae7f
   2:        0x10e3ab015 - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hca543c34f11229ac
   3:        0x10e3aab4f - std::panicking::default_hook::hc2c969e7453d080c
   4:        0x10e36f9b6 - std::sys_common::unwind::begin_unwind_inner::h30e12d15ce2b2e25
   5:        0x10a3bfb44 - std::sys_common::unwind::begin_unwind::h65390c63b501d6ed
   6:        0x10a4d9c81 - _<datum..Datum<'tcx, K>>::to_llscalarish::h195a00339e1a572a
   7:        0x10a4d97ac - _<std..vec..Vec<T> as std..iter..FromIterator<T>>::from_iter::h9d79cca6cff1d802
   8:        0x10a4d0404 - rustc_trans::expr::trans_rvalue_stmt_unadjusted::hce285cdde393b03d
   9:        0x10a42ff28 - rustc_trans::expr::trans_into::he1315719b2222c7c
  10:        0x10a4275ce - rustc_trans::controlflow::trans_block::h4fad28c271095568
  11:        0x10a4cd85a - rustc_trans::expr::trans_rvalue_dps_unadjusted::h4d8aac465b9b8fed
  12:        0x10a42ff58 - rustc_trans::expr::trans_into::he1315719b2222c7c
  13:        0x10a4275ce - rustc_trans::controlflow::trans_block::h4fad28c271095568
  14:        0x10a42608c - rustc_trans::base::trans_closure::h83a389352ac0be25
  15:        0x10a427d3d - rustc_trans::base::trans_fn::h9423938066432dd9
  16:        0x10a432c07 - rustc_trans::base::trans_item::hdc785ae68a9e6500
  17:        0x10a44c946 - _<base..TransItemsWithinModVisitor<'a, 'tcx> as rustc..hir..intravisit..Visitor<'v>>::visit_item::h22c1c36dec64effa
  18:        0x10a44a606 - rustc::hir::intravisit::walk_item::he78478ac5852ebcf
  19:        0x10a43b3be - rustc_trans::base::trans_crate::h6ed1dbd6e572a8c2
  20:        0x1099b622a - rustc_driver::driver::phase_4_translate_to_llvm::hd7579aae98641824
  21:        0x1099b495c - rustc_driver::driver::compile_input::_$u7b$$u7b$closure$u7d$$u7d$::he3c6b6ab9afe28dd
  22:        0x1099b121d - rustc_driver::driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::h06c776ef4d1c70b6
  23:        0x1099aac50 - rustc::ty::context::TyCtxt::create_and_enter::hb0e0e916c7274a64
  24:        0x10997d65f - rustc_driver::driver::compile_input::h0629572e6f316b31
  25:        0x1099602ef - rustc_driver::run_compiler::h8902aebf8b1849a8
  26:        0x10995d682 - std::sys_common::unwind::try::try_fn::h4c74456035d0fcc7
  27:        0x10e39c3cb - __rust_try
  28:        0x10e39c353 - std::sys_common::unwind::inner_try::h47a4d9cd4a369dcd
  29:        0x10995df19 - _<F as std..boxed..FnBox<A>>::call_box::h27f542a39f1d61ef
  30:        0x10e3a9ee8 - std::sys::thread::Thread::new::thread_start::h6f266e069bf4ec2b
  31:     0x7fff88f6d99c - _pthread_body
  32:     0x7fff88f6d919 - _pthread_start

Activity

UnlawfulMonad

UnlawfulMonad commented on Apr 28, 2016

@UnlawfulMonad

I received the same error with this code:

#![allow(dead_code, non_upper_case_globals)]
#![feature(asm)]

#[macro_use]
extern crate lazy_static;

pub mod cpuid;

//SSE
#[repr(C)]
pub struct D32x4(f32,f32,f32,f32);

//SSE2
#[repr(C)]
pub struct D64x2(f64,f64);

#[repr(C)]
pub struct I64x2(i64,i64);
#[repr(C)]
pub struct U64x2(u64,u64);

#[repr(C)]
pub struct I32x4(i32,i32,i32,i32);
#[repr(C)]
pub struct U32x4(u32,u32,u32,u32);

#[repr(C)]
pub struct I16x8(i16,i16,i16,i16,i16,i16,i16,i16);
#[repr(C)]
pub struct U16x8(u16,u16,u16,u16,u16,u16,u16,u16);

#[repr(C)]
pub struct I8x16(i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8,i8);
#[repr(C)]
pub struct U8x16(u8,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8,u8);

pub trait Vector {
    fn add(&self, vec: Self) -> Self;
    fn sub(&self, vec: Self) -> Self;
    fn mul(&self, vec: Self) -> Self;
    fn div(&self, vec: Self) -> Self;
}

impl Vector for D32x4 {
    fn add(&self, vec: Self) -> Self {
        unsafe {
            let ret: Self;
            asm!("
                 movaps $1, %xmm1
                 movaps $2, %xmm2
                 addps %xmm1, %xmm2
                 movaps $xmm1, $0
                 "
                 : "=r"(ret)
                 : "1"(self), "2"(vec)
                 : "{xmm1}", "{xmm2}"
                 );
            ret
        }
    }

    fn sub(&self, vec: Self) -> Self {
        unsafe {
            let ret: Self;
            asm!("
                 movaps $1, %xmm1
                 movaps $2, %xmm2
                 subps %xmm1, %xmm2
                 movaps $xmm1, $0
                 "
                 : "=r"(ret)
                 : "1"(self), "2"(vec)
                 : "{xmm1}", "{xmm2}"
                 );
            ret
        }
    }

    fn mul(&self, vec: Self) -> Self {
        unsafe {
            let ret: Self;
            asm!("
                 movaps $1, %xmm1
                 movaps $2, %xmm2
                 mulps %xmm1, %xmm2
                 movaps $xmm1, $0
                 "
                 : "=r"(ret)
                 : "1"(self), "2"(vec)
                 : "{xmm1}", "{xmm2}"
                 );
            ret
        }
    }

    fn div(&self, vec: Self) -> Self {
        unsafe {
            let ret: Self;
            asm!("
                 movaps $1, %xmm1
                 movaps $2, %xmm2
                 divps %xmm1, %xmm2
                 movaps $xmm1, $0
                 "
                 : "=r"(ret)
                 : "1"(self), "2"(vec)
                 : "{xmm1}", "{xmm2}"
                 );
            ret
        }
    }
}

Meta

Running with RUST_BACKTRACE=1 gives

RUST_BACKTRACE=1 cargo build --verbose
       Fresh lazy_static v0.2.1
   Compiling asm v0.0.1 (file:///home/lsdev/asm)
     Running `rustc src/lib.rs --crate-name asm --crate-type lib -g --out-dir /home/lsdev/asm/target/debug --emit=dep-info,link -L dependency=/home/lsdev/asm/target/debug -L dependency=/home/lsdev/asm/target/debug/deps --extern lazy_static=/home/lsdev/asm/target/debug/deps/liblazy_static-a81b08a56ec46bff.rlib`
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'assertion failed: self.appropriate_rvalue_mode(bcx.ccx()) == ByValue', src/librustc_trans/datum.rs:789
stack backtrace:
   1:     0x7f22f42d6140 - std::sys::backtrace::tracing::imp::write::hf68f1a220b61702c
   2:     0x7f22f42e386b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hb638acea7c29901b
   3:     0x7f22f42e340c - std::panicking::default_hook::h508c3dab3df347d6
   4:     0x7f22f42a844f - std::sys_common::unwind::begin_unwind_inner::h17f9e42de6d55309
   5:     0x7f22f320789f - std::sys_common::unwind::begin_unwind::hedd66fca20b8a1c3
   6:     0x7f22f3307548 - _<datum..Datum<'tcx, K>>::to_llscalarish::h90da49dfa16703f5
   7:     0x7f22f3307378 - core::ops::impls::_<impl std..ops..FnOnce<A> for &'a mut F>::call_once::hb0aa51af534f50de
   8:     0x7f22f3307185 - _<std..vec..Vec<T> as std..iter..FromIterator<T>>::from_iter::hea83d25a10a342bb
   9:     0x7f22f32febc1 - rustc_trans::expr::trans_rvalue_stmt_unadjusted::he6f7be9fa97e15d9
  10:     0x7f22f3275b1f - rustc_trans::expr::trans_into::h67fb303b64e53185
  11:     0x7f22f32d9d1b - rustc_trans::controlflow::trans_stmt_semi::h6dfb389a66ac41c8
  12:     0x7f22f326d2f0 - rustc_trans::controlflow::trans_block::hb0ab7613146bf62c
  13:     0x7f22f32fc530 - rustc_trans::expr::trans_rvalue_dps_unadjusted::hdf00eddfdf40ffbd
  14:     0x7f22f3275b44 - rustc_trans::expr::trans_into::h67fb303b64e53185
  15:     0x7f22f326d61d - rustc_trans::controlflow::trans_block::hb0ab7613146bf62c
  16:     0x7f22f326bb65 - rustc_trans::base::trans_closure::hb994e1a0888be25b
  17:     0x7f22f326dd45 - rustc_trans::base::trans_fn::h88500350326131d7
  18:     0x7f22f3278a69 - rustc_trans::base::trans_item::hda6e7b5dd0b4b42f
  19:     0x7f22f3290d4b - _<base..TransItemsWithinModVisitor<'a, 'tcx> as rustc..hir..intravisit..Visitor<'v>>::visit_item::ha66039a6625cc579
  20:     0x7f22f327f1db - rustc_trans::base::trans_crate::hd61624dbab389bc0
  21:     0x7f22f4846b3f - rustc_driver::driver::phase_4_translate_to_llvm::h02f3cb83bf92a921
  22:     0x7f22f484523b - rustc_driver::driver::compile_input::_$u7b$$u7b$closure$u7d$$u7d$::h828c3d094bf44949
  23:     0x7f22f4841bb0 - rustc_driver::driver::phase_3_run_analysis_passes::_$u7b$$u7b$closure$u7d$$u7d$::he8d0a22aa8076fed
  24:     0x7f22f483b68b - rustc::ty::context::TyCtxt::create_and_enter::h980e1fdb00693075
  25:     0x7f22f483813e - rustc_driver::driver::phase_3_run_analysis_passes::h611c3bbb7fd33763
  26:     0x7f22f480a99f - rustc_driver::driver::compile_input::hd56cf2fd4d4af18d
  27:     0x7f22f47f0f04 - rustc_driver::run_compiler::h0185bb759e59b39b
  28:     0x7f22f47ee361 - std::sys_common::unwind::try::try_fn::hdf9deeebe718955f
  29:     0x7f22f42d38db - __rust_try
  30:     0x7f22f42d386d - std::sys_common::unwind::inner_try::h74a189ca1fbe8e07
  31:     0x7f22f47eebaa - _<F as std..boxed..FnBox<A>>::call_box::hb28490749f4628cc
  32:     0x7f22f42e1a04 - std::sys::thread::Thread::new::thread_start::h40a33956f4cb7596
  33:     0x7f22ece526a9 - start_thread
  34:     0x7f22f3f35e9c - clone
  35:                0x0 - <unknown>

error: Could not compile `asm`.

Caused by:
  Process didn't exit successfully: `rustc src/lib.rs --crate-name asm --crate-type lib -g --out-dir /home/lsdev/asm/target/debug --emit=dep-info,link -L dependency=/home/lsdev/asm/target/debug -L dependency=/home/lsdev/asm/target/debug/deps --extern lazy_static=/home/lsdev/asm/target/debug/deps/liblazy_static-a81b08a56ec46bff.rlib` (exit code: 101)

and my rustc --version --verbose:

rustc 1.9.0-dev (c0221c889 2016-04-11)
binary: rustc
commit-hash: c0221c8897db309a79990367476177b1230bb264
commit-date: 2016-04-11
host: x86_64-unknown-linux-gnu
Aatch

Aatch commented on Apr 29, 2016

@Aatch
Contributor

@drrb while a reproduction case has been provided now, your original report didn't supply any usable information in terms of tracking down the problem. Even now it would be nice to know if your code has any similarities to @tqoitc's to help narrow down the issue.

Aatch

Aatch commented on Apr 29, 2016

@Aatch
Contributor

Ok, so assuming that @drrb is also getting the same error, this is due to inline asm support just being generally bad.

We (currently) only support immediate operands for asm inputs, and D32x4 isn't an immediate, however we don't actually check this until we try and load from the memory location D32x4 is in. Inline ASM needs an overhaul, so this probably won't be fixed directly until that happens.

@tqoitc While investigating this, I tried to fix your ASM so it compiled, here is the fixed version of add:

fn add(&self, vec: &Self) -> Self {
  unsafe {
    let mut ret: Self = std::mem::uninitialized();
    asm!("
      movups $1, %xmm1,
      movups $2, %xmm2,
      addps %xmm1, %xmm2,
      movups %xmm1, $0
      "
      : "=*m"(&mut ret)
      : "*m"(self), "*m"(vec)
      : "xmm1", "xmm2"
  }
}

The main changes are to the constraints, using *m means that this is an indirect memory operand. This does mean you need to initialize ret to something in order to take a pointer to it.

I also changed to using movups, which is just because there's no guarantee that self, vec or ret will be appropriately aligned for movaps.

drrb

drrb commented on Apr 30, 2016

@drrb
Author

Thanks @Aatch, I'm not able to post my code, sorry. I can confirm though that I use a bit of inline ASM. I'll have a look and see if I can find any specific similarities to @tqoitc's code.

Mark-Simulacrum

Mark-Simulacrum commented on May 3, 2017

@Mark-Simulacrum
Member

With @tqoitc's code sample updated to not have clobbers in braces and somewhat minimized, this is the ICE I get. Updated code is also included below.

#![allow(dead_code, non_upper_case_globals)]
#![feature(asm)]

//SSE
#[repr(C)]
pub struct D32x4(f32,f32,f32,f32);

impl D32x4 {
    fn add(&self, vec: Self) -> Self {
        unsafe {
            let ret: Self;
            asm!("
                 movaps $1, %xmm1
                 movaps $2, %xmm2
                 addps %xmm1, %xmm2
                 movaps $xmm1, $0
                 "
                 : "=r"(ret)
                 : "1"(self), "2"(vec)
                 : "xmm1", "xmm2"
                 );
            ret
        }
    }
}
added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
on Jun 4, 2017
added a commit that references this issue on Feb 1, 2021

Rollup merge of rust-lang#81387 - c410-f3r:tests-tests-tests, r=petro…

69f0364
added a commit that references this issue on Feb 1, 2021

Rollup merge of rust-lang#81387 - c410-f3r:tests-tests-tests, r=petro…

11eb176
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Aatch@frewsxcv@drrb@Mark-Simulacrum@UnlawfulMonad

        Issue actions

          Internal Compile Error: thread 'rustc' panicked at 'assertion failed: self.appropriate_rvalue_mode(bcx.ccx()) == ByValue', ../src/librustc_trans/datum.rs:789 · Issue #33264 · rust-lang/rust