Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVM assertion error when dereferencing "&mut Iterator<Item=Something>" from function parameter #21379

Closed
mottalli opened this issue Jan 19, 2015 · 6 comments
Labels
A-associated-items Area: Associated items such as associated types and consts. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@mottalli
Copy link

Offending code:

extern crate core;
use core::fmt;

fn show_all<I: fmt::String>(iter: &mut Iterator<Item=I>) {
    for i in *iter {
        println!("{}", i);
    }
}

fn main() {
    let v = vec![1i32, 2, 3, 4];
    show_all(&mut v.iter());
}

Compiler error (formatted):

rustc: /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/llvm/lib/IR/Instructions.cpp:281: 
void llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&): 
Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && 
"Calling a function with a bad signature!"' failed.

Rust version:

$ rustc --version
rustc 1.0.0-nightly (f4f10dba2 2015-01-17 20:31:08 +0000)
@huonw huonw added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 19, 2015
@mottalli
Copy link
Author

I compiled Rust from source and the previous error becomes this:

Call parameter type does not match function signature!
  %11 = load { i8*, void (i8*)** }* %__fat_ptr
 { i8*, void (i8*)** }*  %12 = call i8* @"_ZN216fn$LP$$BP$mut$u{20}core..iter..Iterator$u{20}$u{2b}$u{20}$u{27}static$RP$$u{20}.$GT$$u{20}core..option..Option$LT$$LT$core..iter..Iterator$u{20}$u{2b}$u{20}$u{27}static$u{20}as$u{20}core..iter..Iterator$GT$..Item$GT$16object_shim.166317h29bc7de23a846978E"({ i8*, void (i8*)** } noalias nocapture dereferenceable(16) %11)
LLVM ERROR: Broken function found, compilation aborted!

Rust version:

$ rustc --version
rustc 1.0.0-dev (dcaeb6aa2 2015-01-18 11:28:53 +0000)

@mottalli
Copy link
Author

I found out that the problem is on the loop:

    for i in *iter {
        println!("{}", i);
    }

If I replace this with the expanded version of the loop:

    loop {
        match (*iter).next() {
            Some(ref i) => println!("{}", i),
            None => break
        }
    }

it compiles and works as expected. So, the problem seems to be that the compiler is unable to dereference the Iterator trait, maybe it has something to do with the fact that I am forcing Item to be of a specific type? (i.e. Iterator<Type=I>)

@mottalli mottalli changed the title LLVM assertion error when using Iterator<Item=Something> as function parameter LLVM assertion error when dereferencing "&mut Iterator<Item=Something>" from function parameter Jan 20, 2015
@theemathas
Copy link

Minimal code:

fn foo(it: &mut Iterator<Item = i32>) {
    for x in *it {}
}

fn main() { }

playpen

The ICE:

rustc: /build/rust-git/src/rust/src/llvm/lib/IR/Instructions.cpp:281: void llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.

Removing the associated type results in a variant of #21137

@nikomatsakis nikomatsakis added the A-associated-items Area: Associated items such as associated types and consts. label Jan 26, 2015
@nikomatsakis
Copy link
Contributor

Gah, I feel like I've fixed this bug once before.

@japaric
Copy link
Member

japaric commented Jan 26, 2015

Duplicate of #20605

To avoid the LLVM assertion, don't dereference the iterator in the for loop. This doesn't crash:

fn foo(it: &mut Iterator<Item = i32>) {
    for x in it {}
//~^ error: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
}

fn main() { }

Instead, you get a compiler error, I think that compiler error maybe be a different bug.

@japaric
Copy link
Member

japaric commented Jan 26, 2015

I filled issue #21655 for the for _ in ref_mut_trait_object {} bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items such as associated types and consts. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants