abhigyanpatwari/GitNexus · warning

[cfg] unresolved goto label "${label}" routed to EXIT (${fro

Error message

[cfg] unresolved goto label "${label}" routed to EXIT (${froms.length} site(s))

What it means

In the C/C++ CFG builder's finishGotos(), a forward goto statement's target label was never seen while walking the function body — typically because the label is produced by a header macro or the source is malformed. To keep the CFG single-exit the jump is routed to the EXIT node, and every unresolved label is logged via console.warn (the builder's warn path) so a dropped jump is never silent (R4).

Source

Thrown at gitnexus/src/core/ingestion/cfg/visitors/c-cpp.ts:574

  }

  private labelOf(stmt: SyntaxNode): string | undefined {
    const id =
      stmt.childForFieldName('label') ??
      stmt.namedChildren.find((c) => c.type === 'statement_identifier');
    return id?.text;
  }

  /**
   * Drain any forward gotos whose label never appeared in the function (a label
   * defined in a header macro, or malformed source) — route them to EXIT so the
   * graph stays single-exit. Logs via console.warn (the builder's warn path)
   * so a dropped jump is never silent (R4). Called once after the body walk.
   */
  finishGotos(): void {
    for (const [label, froms] of this.pendingGotos) {
      // eslint-disable-next-line no-console
      console.warn(
        `[cfg] unresolved goto label "${label}" routed to EXIT (${froms.length} site(s))`,
      );
      for (const from of froms) this.builder.edge(from, this.builder.exitIndex, 'seq');
    }
    this.pendingGotos.clear();
  }
}

/**
 * C++ walk — extends the C core with exception flow and the range-for loop.
 * These node types never appear in a C parse, so no language conditional is
 * needed; the C core dispatches them through {@link visitExtra}.
 */
class CppCfgWalk extends CCfgWalk {
  protected override visitExtra(stmt: SyntaxNode): SeqResult | undefined {
    switch (stmt.type) {
      case 'for_range_loop':
        return this.visitForRange(stmt);

View on GitHub (pinned to aac7515d2a)

Solutions

  1. Check whether the label is defined inside a macro in a header; inline the label or exclude such files if full CFG fidelity is not needed
  2. Fix malformed source — in compilable code every goto label exists in the same function
  3. Accept the EXIT routing for analysis purposes; it is a deliberate degradation that keeps the graph single-exit and the drop is now observable

Example fix

// before — label hidden in a header macro (util.h: #define DONE done:)
int f(void) { goto done; DONE return 0; }

// after — label inline in the function
int f(void) { goto done; done: return 0; }
Defensive patterns

Strategy: fallback

Validate before calling

// Pre-check: flag gotos whose label is not literally defined in the file
const gotoLabels = [...source.matchAll(/\bgoto\s+([A-Za-z_]\w*)\s*;/g)].map((m) => m[1]);
const defined = new Set([...source.matchAll(/^\s*([A-Za-z_]\w*)\s*:/gm)].map((m) => m[1]));
const unresolved = gotoLabels.filter((l) => !defined.has(l));
if (unresolved.length > 0) {
  console.warn(`macro-hidden or missing labels: ${[...new Set(unresolved)].join(', ')}`);
}

Type guard

function hasResolvableGotoLabels(source: string): boolean {
  const gotos = [...source.matchAll(/\bgoto\s+([A-Za-z_]\w*)\s*;/g)].map((m) => m[1]);
  const defined = new Set([...source.matchAll(/^\s*([A-Za-z_]\w*)\s*:/gm)].map((m) => m[1]));
  return gotos.every((l) => defined.has(l));
}

Prevention

When it happens

Trigger: A goto whose label text comes from a macro defined in a header; preprocessed or partial C/C++ source where the label is absent; genuinely malformed code with a goto to a label that does not exist in the function (parses but would not compile).

Common situations: Macro-heavy legacy C where labels hide behind #define'd blocks; generated C being indexed; analysis of snippets that do not compile on their own.

Related errors


AI-assisted analysis of abhigyanpatwari/GitNexus@aac7515d2a (2026-08-20). Data as JSON: /api/errors/af942c0794ad691e. Report an issue: GitHub.