mlir-rs/melior

Segfault using ODS llvm alloca builder

Closed this issue · 0 comments

edg-l commented
Caused by:
  process didn't exit successfully: `/snip/melior/target/debug/deps/melior-eb2c58f5b3bbae69 compile_ods_llvm_alloca` (signal: 11, SIGSEGV: invalid memory reference)

#[test]
    fn compile_ods_llvm_alloca() {
        let context = create_test_context();

        let location = Location::unknown(&context);
        let mut module = Module::new(location);
        let integer_type = IntegerType::new(&context, 64).into();
        let ptr_type = crate::dialect::llvm::r#type::opaque_pointer(&context);

        module.body().append_operation(func::func(
            &context,
            StringAttribute::new(&context, "foo"),
            TypeAttribute::new(FunctionType::new(&context, &[integer_type], &[]).into()),
            {
                let block = Block::new(&[(integer_type, location)]);

                let alloca_size = block.argument(0).unwrap().into();

                block.append_operation(
                    llvm::AllocaOpBuilder::new(location)
                        .alignment(IntegerAttribute::new(
                            8,
                            IntegerType::new(&context, 64).into(),
                        ))
                        .array_size(alloca_size)
                        .res(ptr_type)
                        .build()
                        .into(),
                );

                block.append_operation(func::r#return(&[], location));

                let region = Region::new();
                region.append_block(block);
                region
            },
            &[],
            location,
        ));

        convert_module(&context, &mut module);

        assert!(module.as_operation().verify());
        insta::assert_display_snapshot!(module.as_operation());
    }