Skip to content

llvm::StructType::getElementType: Assertion `N < NumContainedTys && "Element number out of range!"' failed. #21721

@eddyb

Description

@eddyb
pub fn maybe_ptr() -> *const u8 {
    static NONE: Option<((), &'static u8)> = None;
    unsafe {
        *(&NONE as *const _ as *const *const u8)
    }
}

Running this in the playpen gives:

rustc: /build/rust-git/src/rust/src/llvm/include/llvm/IR/DerivedTypes.h:285: llvm::Type* llvm::StructType::getElementType(unsigned int) const: Assertion `N < NumContainedTys && "Element number out of range!"' failed.
Aborted (core dumped)

This is actually happening inside LLVM optimizations, in the early-cse pass (-C opt-level=1 still triggers it). Originally found in a memcpy optimized into a load.
Reduced LLVM IR:

target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@NONE = internal constant { { {}, i8* } } zeroinitializer

define i8* @maybe_ptr() {
entry-block:
  %0 = load i8** bitcast ({ { {}, i8* } }* @NONE to i8**)
  ret i8* %0
}

cc @dotdash

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions