Skip to content

LLVM Assertion Failure “Ptr must be a pointer to Val type!” #22346

Closed
@yggie

Description

@yggie

I ran into a very strange issue today, the code that can replicate the issue is as follows:

struct Foo;

impl Foo {
    fn iter(&self) -> Box<Iterator<Item=usize>> {
      return Box::new(range(0, 3).map(|i| { return i; }));
    }
}

fn main() {
  for i in Foo.iter() {
    println!("{:?}", i);
  }
}

This generates the following error on the Rust playpen:

rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/lib/IR/Instructions.cpp:1083: void llvm::StoreInst::AssertOK(): Assertion `getOperand(0)->getType() == cast<PointerType>(getOperand(1)->getType())->getElementType() && "Ptr must be a pointer to Val type!"' failed.
Aborted (core dumped)
playpen: application terminated with error code 134

A minor change to the closure fixes the issue:

// ...
      return Box::new(range(0, 3).map(|i| i )); // without the explicit return inside the closure
// ...

This variant also works:

// ...
      Box::new(range(0, 3).map(|i| { return i; })) // without the explicit return outside the closure
// ...

If it helps, this is the output from rustc --version --verbose

rustc 1.0.0-nightly (b9ba643b7 2015-02-13 21:15:39 +0000)
binary: rustc
commit-hash: b9ba643b72ea6104bcb1209d238f6b445e3b51fc
commit-date: 2015-02-13 21:15:39 +0000
host: x86_64-apple-darwin
release: 1.0.0-nightly

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