Skip to content

LLVM assertion with extern fn in struct #4360

Closed
@veddan

Description

@veddan
extern fn plusone(u: u8) -> u8 {
    return u + 1;
}

struct S {
    fun: *u8
}

const s: S = S { fun: plusone };

This code does not give any compile errors from rustc, but triggers an assertion in LLVM: "Initializer for struct element doesn't match struct element type!".

Full error message:

rustc: .../rust/src/llvm/lib/VMCore/Constants.cpp:812: llvm::ConstantStruct::ConstantStruct(llvm::StructType*, llvm::ArrayRef<llvm::Constant*>): Assertion `(T->isOpaque() || V[i]->getType() == T->getElementType(i)) && "Initializer for struct element doesn't match struct element type!"' failed.```

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions