Skip to content

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

Closed
@AnthIste

Description

@AnthIste

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    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

    Issue actions