Skip to content

LLVM assertion getting a reference out of tuple #4760

Closed
@erickt

Description

@erickt

Alexander was having trouble on the mailing list doing this:

pub trait TupleVal<T> {
    pub pure fn _1(&self) -> &self/T;
}

impl <T>(T, T): TupleVal<T> {
    pure fn _1(&self) -> &self/T {
        //match *self { (ref a, _) => a }
        let &(ref a, _) = self;
        a
    }
}

fn main() {
    let pair = (1, 2);
    let left = *pair._1();
    io::println(fmt!("pair left: %u", left));
}

This results in the following llvm error:

Assertion failed: (getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"), function AssertOK, file /Users/erickt/Projects/rust/rust/src/llvm/lib/VMCore/Instructions.cpp, line 1062

If instead we use the commented out llvm form, it compiles and runs perfectly fine, so the let destructuring mechanism is probably to blame. @catamorphism: You wrote that code, right? Can you take a look at this?

Also, I ran into a similar llvm assertion in #4759, so maybe it's the same bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-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