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

Compiler segfault / illegal instruction: llvm: Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed. #27455

Closed
AnthIste opened this issue Aug 1, 2015 · 2 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@AnthIste
Copy link

AnthIste commented Aug 1, 2015

Environment

Local Environment

Darwin genesis.local 14.4.0 Darwin Kernel Version 14.4.0: Thu May 28 11:35:04 PDT 2015; root:xnu-2782.30.5~1/RELEASE_X86_64 x86_64
rustc 1.0.0 (a59de37e9 2015-05-13) (built 2015-05-14)

Playpen Environment

This was tested 01/07/2015. I am not sure how to get the exact versions from the playpen.

Error

On 1.0.0 Stable (tested on local environment)

rustc src/lib.rs --crate-name ecs --crate-type lib -g --test -C metadata=33fec8143b6dd287 -C extra-filename=-33fec8143b6dd287 --out-dir /Users/salad/Code/Rust/ecs/target/debug --emit=dep-info,link -L dependency=/Users/salad/Code/Rust/ecs/target/debug -L dependency=/Users/salad/Code/Rust/ecs/target/debug/deps
src/lib.rs:8:5: 8:19 warning: struct field is never used: `entity`, #[warn(dead_code)] on by default
src/lib.rs:8     entity: Entity,
                 ^~~~~~~~~~~~~~
[1]    10781 segmentation fault  rustc src/lib.rs --crate-name ecs --crate-type lib -g --test -C  -C  --out-di

On 1.1.0 Stable (tested on playpen)

Illegal instruction (core dumped)
playpen: application terminated with error code 132

On nightly (tested on playpen)

rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/include/llvm/IR/Instructions.h:823: llvm::Type* llvm::checkGEPType(llvm::Type*): Assertion `Ty && "Invalid GetElementPtrInst indices for type!"' failed.
Aborted (core dumped)
playpen: application terminated with error code 134

Notes

This only occurs when trying to compile and run the test cast using cargo test. Simply building the example with cargo build works as expected (no crash).

Related Issues

I searched for related issues but they all seem to be solved, and this is still occurring. Hence I am opening a new issue instead. The related issues that I found with a similar assertion:

Minimal Reproducable Example

Thanks to @arielb1

trait SomeTrait {}
impl SomeTrait for i32 {}
struct Component<T:?Sized>(T);
fn main() {
    let ref c = Component(42);
    let &Component(ref data) = c as &Component<SomeTrait>;
}

Full Code Snippet

use std::any::Any;

struct Entity(u64);

struct Component<T: ?Sized>(T);

struct EntityData {
    entity: Entity,
    components: Vec<Box<Component<Any>>>,
}

impl EntityData {
    pub fn new() -> Self {
        EntityData {
            entity: Entity(0),
            components: Vec::new(),
        }
    }

    pub fn attach<T: Sized + Any>(&mut self, data: T) {
        let c = Component(data);
        let x = Box::new(c);

        self.components.push(x);
    }

    pub fn get<T: Any>(&self) -> Option<&T> {
        let first = &self.components[0];

        let Component(ref data) = **first;

        data.downcast_ref::<T>()
    }
}

#[test]
pub fn attach_and_get() {
    let mut e = EntityData::new();
    let c = Component::<u64>(1234);

    e.attach(c);

    let u = e.get::<u64>().unwrap();

    assert!(*u == 1234);
}
@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Aug 1, 2015
@arielb1
Copy link
Contributor

arielb1 commented Aug 1, 2015

Mini:

trait SomeTrait {}
impl SomeTrait for i32 {}
struct Component<T:?Sized>(T);
fn main() {
    let ref c = Component(42);
    let &Component(ref data) = c as &Component<SomeTrait>;
}

This seems like a known issue with _match

@steveklabnik
Copy link
Member

This ICE seems to be fixed on

rustc 1.12.0-nightly (b30eff7ba 2016-08-05)

I have a hunch that this is due to MIR being turned on, though I'm not sure. Please let me know if this still ICEs for you, but closing for now 🎊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants