TomBebbington / llvm-rs

LLVM wrappers for Rust
BSD 3-Clause "New" or "Revised" License
68 stars 27 forks source link

crash when calling build_gep with a compiled 0usize #31

Open sapir opened 6 years ago

sapir commented 6 years ago

crashing code:

extern crate llvm;
use llvm::*;

fn main() {
    let context = Context::new();
    let module = Module::new("test", &context);

    let u8_type = Type::get::<u8>(&context);
    let array_type = ArrayType::new(u8_type, 32);
    let struct_type = StructType::new(
        &context,
        &[
            array_type,
        ],
        false);
    let struct_ptr_type = PointerType::new(struct_type);

    let void_type = Type::get::<()>(&context);
    let fn_type = FunctionType::new(
        void_type,
        &[struct_ptr_type]);

    let func = module.add_function("test_func", fn_type);
    let first_block = func.append("a_block");
    let builder = Builder::new(&context);
    builder.position_at_end(first_block);

    let arg_ptr = &func[0];
    let zero = 0usize.compile(&context);
    builder.build_gep(arg_ptr, &[zero, zero]);
}

if I change 0usize to 0u32 then it doesn't crash.