Skip to content

feat(cfg+scan+output): wire C/C++ pipeline end-to-end#677

Merged
shivasurya merged 2 commits intomainfrom
shiva/cpp-cfg-scan
May 3, 2026
Merged

feat(cfg+scan+output): wire C/C++ pipeline end-to-end#677
shivasurya merged 2 commits intomainfrom
shiva/cpp-cfg-scan

Conversation

@shivasurya
Copy link
Copy Markdown
Owner

Summary

Three integration changes that bring C/C++ analysis into the full pathfinder scan pipeline.

1. CFG handlers (graph/callgraph/cfg/builder.go)

Adds processSwitch and processDoWhile so C/C++ control-flow surfaces in the CFG instead of falling through to the generic statement handler.

Construct Shape
switch (x) { case 1: ...; case 2: ...; default: ... } [BlockTypeSwitch header] fans out to one case block per case_statement, with fallthrough edges between consecutive cases and a merge block reachable from every case.
do { body } while (cond); [pred] -> [body] -> [BlockTypeLoop cond], cond loops back to body and falls through to an after-block.

The do-while shape (no header gate before the first iteration) preserves the "execute body at least once" semantics that distinguishes it from a plain while.

2. Scan integration (cmd/scan.go)

After the existing Go block, the scan now:

  • Calls BuildCModuleRegistry + BuildCCallGraph when the parsed CodeGraph carries any C-tagged node, then merges the result via MergeCallGraphs.
  • Same for C++ with BuildCppModuleRegistry + BuildCppCallGraph.

Each step is gated by the new hasLanguageNodes(codeGraph, language) helper so a Python-only or Go-only project skips the C/C++ work entirely. Build failures log a warning and let the scan continue with whatever languages did build — matching the Go path.

3. Enricher (output/enricher.go)

extractFunctionFromFQN and fallbackLocation learn to handle C/C++ scope-resolved FQNs:

FQN Function ClassName RelPath
src/main.c::main main (empty) src/main.c
src/socket.cpp::mylib::Socket::connect connect Socket src/socket.cpp
myapp.auth.login (regression) login auth (existing path)

The dot-separated branch for Python / Go / Java is preserved; the :: branch only fires when the FQN actually contains ::.

Test plan

  • go build ./...
  • go test ./... — full suite green
  • go vet ./...
  • golangci-lint run ./graph/callgraph/cfg/ ./cmd/ ./output/ — 0 issues
  • Coverage on changed functions: processSwitch 92.3%, processDoWhile 100%, hasLanguageNodes 100%, fallbackLocation 100%, extractFunctionFromFQN 85.7% (the unreachable terminal return is pre-existing dead code)
  • CFG: switch with 3 cases + default, fallthrough between consecutive cases, empty switch body, do-while body + cond + after, body executes before loop header
  • Scan: nil graph, empty graph, no matching nodes, multiple languages
  • Enricher: C FQN (no class), C++ FQN with namespace + class, missing-file FQN falls through cleanly, dot-separated regression cases

Stacked on

shiva/cpp-statements (#676)

@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels May 3, 2026
@shivasurya shivasurya self-assigned this May 3, 2026
@safedep
Copy link
Copy Markdown

safedep Bot commented May 3, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep Github App

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 6
Rules 205

Powered by Code Pathfinder

@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2026

Codecov Report

❌ Patch coverage is 91.07143% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.43%. Comparing base (1a3f8b4) to head (e2ae095).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sast-engine/cmd/scan.go 80.00% 5 Missing and 2 partials ⚠️
sast-engine/graph/callgraph/cfg/builder.go 94.82% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #677      +/-   ##
==========================================
+ Coverage   85.37%   85.43%   +0.06%     
==========================================
  Files         187      187              
  Lines       27164    27276     +112     
==========================================
+ Hits        23190    23303     +113     
+ Misses       3083     3082       -1     
  Partials      891      891              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Owner Author

shivasurya commented May 3, 2026

Merge activity

  • May 3, 1:15 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 3, 1:33 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 3, 1:34 PM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya changed the base branch from shiva/cpp-statements to graphite-base/677 May 3, 2026 13:31
@shivasurya shivasurya changed the base branch from graphite-base/677 to main May 3, 2026 13:32
shivasurya and others added 2 commits May 3, 2026 13:33
Three integration changes that bring C/C++ analysis into the full
scan pipeline:

  1. CFG: add processSwitch and processDoWhile handlers. Switch
     emits a BlockTypeSwitch header with one case-block fan-out per
     case_statement, fallthrough edges between consecutive cases,
     and a merge block reachable from every case. Do-while emits
     `[pred] -> [body] -> [cond]` with the cond block looping back
     to the body and a fall-through to the after-block, matching
     the "execute body at least once" semantics.

  2. cmd/scan.go: build the C call graph after the Go block when the
     CodeGraph carries any node tagged Language="c"; same for C++.
     The hasLanguageNodes helper gates each builder so non-C/C++
     projects skip the work entirely. Build failures log a warning
     and let the scan continue with whatever languages did build.

  3. output/enricher.go: extractFunctionFromFQN and fallbackLocation
     learn to handle C/C++ scope-resolved FQNs ("relpath::funcname",
     "relpath::ns::Class::method"). The existing dot-separated path
     for Python/Go/Java is preserved; the "::" branch is only taken
     when the FQN contains it.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Pull the C/C++ build-and-merge block out of the scanCmd.RunE
closure into three small helpers:

  buildClikeCallGraphs    — entry point gated by hasLanguageNodes
  buildCCallGraphAndMerge — C-only build + merge with warning path
  buildCppCallGraphAndMerge — C++-only build + merge

The closure now reads as one line. The helpers take *CallGraph,
*CodeGraph, projectPath, and *Logger explicitly so they're
unit-testable, which lifts patch coverage on this PR back above
the 85% threshold.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@shivasurya shivasurya force-pushed the shiva/cpp-cfg-scan branch from b3fad0e to e2ae095 Compare May 3, 2026 13:33
@shivasurya shivasurya merged commit afb74f1 into main May 3, 2026
6 checks passed
@shivasurya shivasurya deleted the shiva/cpp-cfg-scan branch May 3, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant