Skip to content

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

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

Activity

  1. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on Jan 28, 2015
  2. eddyb commented on Jan 28, 2015

    @eddyb
    ContributorAuthor

    Current LLVM fork tip: rust-lang/llvm@b820135 on top of llvm-mirror/llvm@0ad623b.

  3. dotdash commented on Feb 15, 2015

    @dotdash
    Contributor
  4. added a commit that references this issue on Feb 19, 2015
    d6d405e
  5. added a commit that references this issue on Feb 21, 2015
    6957bb6
  6. added 2 commits that reference this issue on Feb 21, 2015
    1ce1596
  7. 7 remaining items

  8. eddyb commented on Feb 24, 2015

    @eddyb
    ContributorAuthor

    This needs a test, and there's also two hacks introduced by #21744, that should be reverted now that the LLVM bug is fixed (they both reference this issue).

  9. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Feb 24, 2015
  10. reopened this on Feb 24, 2015
  11. dotdash commented on Feb 24, 2015

    @dotdash
    Contributor

    @eddyb will you take care of that?

  12. added a commit that references this issue on Feb 26, 2015
    f943de9
  13. pczarn commented on Feb 26, 2015

    @pczarn
    Contributor

    I'm still getting this failure in #21973 during the compilation of rustc-trans

  14. dotdash commented on Feb 27, 2015

    @dotdash
    Contributor

    I guess you get that in stage0? That will need a new snapshot, so that the
    stage0 compiler also uses the new LLVM
    Am 26.02.2015 20:40 schrieb "Piotr Czarnecki" notifications@github.com:

    I'm still getting this failure in #21973
    #21973

    —
    Reply to this email directly or view it on GitHub
    #21721 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions