Skip to content

Memory leak: Phi instructions not released in SSA construction #275

@jserv

Description

@jserv

Description

Memory leak detected in the SSA construction phase where phi instructions are not properly released after use, causing unnecessary memory consumption that grows with program complexity.

Current Behavior

  • Phi instructions allocated during SSA construction remain in memory after they're no longer needed
  • Memory usage increases unnecessarily with program size

Expected Behavior

Phi instructions should be properly freed after SSA construction completes to prevent memory leaks.

Location in Code

  • Primary location: src/ssa.c
  • Function: solve_phi_params()
  • Comment in code: "FIXME: dangling phi causes memory leak. Should release phi here."

Impact

  • Memory consumption grows unnecessarily with program complexity
  • Can affect compilation of large programs
  • Reduces efficiency of the self-hosting compiler

Test Case

// Large program with many control flow paths will show increased memory usage
int complex_function(int n) {
    int result = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            result += i;
        } else {
            result -= i;
        }
        // More complex control flow increases phi nodes
        for (int j = 0; j < i; j++) {
            if (j % 3 == 0) {
                result *= 2;
            }
        }
    }
    return result;
}

Proposed Solution

Add proper cleanup code to release phi instructions after they're no longer needed in the SSA construction phase.

References

  • Related to SSA (Static Single Assignment) form optimization
  • Affects memory management in INSN_ARENA

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions