Skip to content

Instantly share code, notes, and snippets.

@japaric
Last active August 29, 2015 14:10
Show Gist options
  • Save japaric/ffca1e1eb50002caa56d to your computer and use it in GitHub Desktop.
Save japaric/ffca1e1eb50002caa56d to your computer and use it in GitHub Desktop.
LLVM assertion
#![feature(lang_items)]
#![crate_type = "rlib"]
#![no_std]
// This core crate has an `Option` that uses unboxed closures (see #19467)
extern crate core;
use core::prelude::{Iterator, IteratorExt, Option, None};
use core::slice::SlicePrelude;
struct ElementSwaps {
sdir: &'static [uint],
}
impl Iterator<()> for ElementSwaps {
// This attribute triggers the assertion
#[inline]
fn next(&mut self) -> Option<()> {
self.sdir.
iter().
max_by(|&sd| sd);
None
}
}
  1. Build a rustc that includes rust-lang/rust#19449

  2. Checkout rust-lang/rust#19467

  3. Bootstrap (2) using (1) as stage-0 compiler, pass RUSTLFLAGS=-Ccodegen-units=2, you should hit an LLVM assertion (see below) while building stage0/libcollections.

  4. Alternatively compile the collections.rs (see above) file using the rustc from (1) and passing the -Ccodegen-units=2 flag.

$ LD_LIBRARY_PATH=/home/japaric/tmp/rust/build/x86_64-unknown-linux-gnu/stage0/lib \
/home/japaric/tmp/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc \
-Ccodegen_units=2 \
collections.rs
collections.rs:9:1: 11:2 warning: struct is never used: `ElementSwaps`, #[warn(dead_code)] on by default
collections.rs:9 struct ElementSwaps {
collections.rs:10 sdir: &'static [uint],
collections.rs:11 }
rustc: /var/tmp/paludis/build/dev-lang-rust-scm/work/rust-scm/src/llvm/lib/IR/Constants.cpp:1609: static llvm::Constant* llvm::ConstantExpr::getPointerCast(llvm::Constant*, llvm::Type*): Assertion `S->getType()->isPtrOrPtrVectorTy() && "Invalid cast"' failed.
./reduce.sh: line 6: 9793 Aborted (core dumped) LD_LIBRARY_PATH=/home/japaric/tmp/rust/build/x86_64-unknown-linux-gnu/stage0/lib /home/japaric/tmp/rust/build/x86_64-unknown-linux-gnu/stage0/bin/rustc -Ccodegen_units=2 collections.rs 2>&1
@nikomatsakis
Copy link

I was able to reduce to this

#![feature(lang_items, unboxed_closures)]

#![crate_type = "rlib"]
#![no_std]

// This core crate has an `Option` that uses unboxed closures (see #19467)
extern crate core;

use core::prelude::{Iterator, IteratorExt, Option, None};
use core::slice::SlicePrelude;

static x: &'static [uint] = &[];

#[inline]
fn next() -> Option<()> {
    x.iter().max_by(|_| 0i);
    None
}

@nikomatsakis
Copy link

further reduction:

#![feature(lang_items, unboxed_closures)]

#![crate_type = "rlib"]
#![no_std]
#![allow(dead_code)]

// This core crate has an `Option` that uses unboxed closures (see #19467)
extern crate core;

use core::prelude::{IteratorExt};
use core::slice::SlicePrelude;

static X: &'static [uint] = &[];

#[inline]
fn next() {
    X.iter().max_by(|_| 0i);
}



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