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

Cranelift: Infinite loop in cranelift-frontend's variable ssa state machine #2903

Closed
Mrmaxmeier opened this issue May 12, 2021 · 2 comments
Closed
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator

Comments

@Mrmaxmeier
Copy link
Contributor

I'm experimenting with some cranelift codegen and I'm seeing a hang/OOM related to the variable ssa resolver.

Here's a minimal reproducer (for cranelift/frontend/src/frontend.rs):

#[test]
fn ssa_state_machine_hang() {
    let sig = Signature::new(CallConv::SystemV);

    let mut fn_ctx = FunctionBuilderContext::new();
    let mut func = Function::with_name_signature(ExternalName::testcase("sample"), sig);
    {
        let mut builder = FunctionBuilder::new(&mut func, &mut fn_ctx);

        let a = Variable::new(0);
        builder.declare_var(a, I32);

        let entry = builder.create_block();
        let block1 = builder.create_block();
        let use_block = builder.create_block();

        // fill entry block
        builder.switch_to_block(entry);
        use cranelift_codegen::ir::TrapCode;
        builder.ins().trap(TrapCode::User(0));

        // fill block1 with back edge
        builder.switch_to_block(block1);
        let cond = builder.ins().iconst(I32, 0);
        builder.ins().brnz(cond, block1, &[]);
        builder.ins().jump(use_block, &[]);

        // use variable in use_block
        builder.switch_to_block(use_block);
        let _ = builder.use_var(a);
        builder.ins().return_(&[]);

        println!("sealing blocks...");
        builder.seal_all_blocks(); // hangs
        builder.finalize();
    }
    println!("{}", func.display(None).to_string());
}

It hangs in seal_all_blocks -> run_state_machine with a huge/growing self.calls vec.

Versions and Environment

Cranelift version or commit: v0.73.0 and current main

@Mrmaxmeier Mrmaxmeier added bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator labels May 12, 2021
@bjorn3
Copy link
Contributor

bjorn3 commented May 12, 2021

I think the problem here is that block1 has a single predecessor (itself) and it tries to handle this single predecessor first

@Mrmaxmeier
Copy link
Contributor Author

It looks like this was also discovered in #3094 and fixed in 6a9378e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Incorrect behavior in the current implementation that needs fixing cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

No branches or pull requests

2 participants