Skip to content

Add isolated CGraphBuilder structuring test harness #184

Description

@artemdinaburg

Problem

patchir-decomp currently has good black-box fixture coverage, but the new direct path still lacks an isolated harness for testing CFG construction and future structuring behavior before Clang emission.

That makes it hard to verify:

  • CGraphBuilder node/successor construction
  • branch metadata extraction from CBRANCH / BRANCHIND
  • future SNode fold/structuring rules
  • negative cases that should fail before codegen

Proposed Work

Add a small AST/decomp unit-style harness that:

  1. deserializes a JSON fixture into the existing Ghidra in-memory model
  2. creates a FunctionBuilder
  3. runs BuildCGraph
  4. asserts directly on CGraph contents before EmitClangAST
  5. when structuring is wired in, asserts on resulting SNode kinds as well

Suggested Implementation

Recommended shape:

  • new test target under the AST/decomp area, preferably gtest-based if that is already acceptable for host-side unit tests
  • helper that constructs a minimal clang::CompilerInstance / ASTContext once per test case
  • fixture loader that reuses patchestry::ghidra::JsonParser
  • focused assertions on:
    • entry node id
    • node count
    • succs / preds
    • branch_cond
    • switch_cases
    • collapsed/structured node metadata once fold rules are active

First Test To Add

A minimal conditional JSON fixture that proves:

  • CBRANCH is removed from block statements
  • BuildCGraph produces two outgoing edges
  • branch_cond is preserved on the CFG node
  • the true/false target blocks are resolved in the expected order

Why This Matters

The current integration tests tell us whether final CIR/C/LLVM output looks reasonable, but they do not localize failures well when CFG structuring changes. This harness would let us test the direct path where the new architecture actually lives.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions