Extract typed C facts for search and lineage #24

Merged
JayKobe6k merged 3 commits from issue-7-c-facts into main 2026-09-04 00:50:17 +00:00
Owner

Summary

  • expand the language-neutral IR with typed scopes, complete declaration types, aggregate and enum structure, signatures, operations, definition sites, unsupported facts, and validated CFG relationships
  • recursively lower owned libclang facts for initializers, assignments, expressions, direct and indirect calls, returns, branches, loops, and conservative unsupported constructs
  • preserve spelling and expansion provenance, deterministic identities, C17/C23 prototype semantics, and producer-before-consumer operation ordering
  • add comprehensive C fixtures, negative builder validation tests, deterministic repeated-indexing coverage, and supported-fact policy documentation

Tests

  • nix develop --command cargo fmt --all -- --check
  • nix develop --command cargo lint
  • nix develop --command cargo test --all-targets --all-features
  • nix develop --command cargo doc --no-deps --all-features
  • nix develop --command cargo check --target x86_64-pc-windows-gnu --all-targets --all-features
  • nix develop --command nixfmt --check flake.nix
  • nix flake check

Closes #7

## Summary - expand the language-neutral IR with typed scopes, complete declaration types, aggregate and enum structure, signatures, operations, definition sites, unsupported facts, and validated CFG relationships - recursively lower owned libclang facts for initializers, assignments, expressions, direct and indirect calls, returns, branches, loops, and conservative unsupported constructs - preserve spelling and expansion provenance, deterministic identities, C17/C23 prototype semantics, and producer-before-consumer operation ordering - add comprehensive C fixtures, negative builder validation tests, deterministic repeated-indexing coverage, and supported-fact policy documentation ## Tests - `nix develop --command cargo fmt --all -- --check` - `nix develop --command cargo lint` - `nix develop --command cargo test --all-targets --all-features` - `nix develop --command cargo doc --no-deps --all-features` - `nix develop --command cargo check --target x86_64-pc-windows-gnu --all-targets --all-features` - `nix develop --command nixfmt --check flake.nix` - `nix flake check` Closes #7
Extract typed C facts for lineage
All checks were successful
Validate / Formatting, linting, and tests (push) Successful in 4m8s
Validate / Formatting, linting, and tests (pull_request) Successful in 3m58s
c17da99b23
JayKobe6k left a comment

Found two actionable semantic extraction issues.

Found two actionable semantic extraction issues.
@ -377,0 +612,4 @@
} else if kind == EntityKind::VarDecl {
let block = self.ensure_current_block(callable, current)?;
let mut context = OperationContext::callable(callable, block);
self.lower_initialization(entity, &mut context)?;
Author
Owner

[P1] Block-scope static declarations are emitted into the function entry block like automatic initializers, but C initializes these objects once before program start rather than on each function entry. Downstream reaching-definition and lineage analysis will therefore model a fresh assignment on every call. Please represent static-storage initialization outside the per-invocation CFG, or mark it with distinct initialization semantics.

[P1] Block-scope `static` declarations are emitted into the function entry block like automatic initializers, but C initializes these objects once before program start rather than on each function entry. Downstream reaching-definition and lineage analysis will therefore model a fresh assignment on every call. Please represent static-storage initialization outside the per-invocation CFG, or mark it with distinct initialization semantics.
@ -377,0 +731,4 @@
let Some(declaration) = self.ensure_declaration(entity)? else {
return Ok(());
};
let Some(initializer) = variable_initializer(entity) else {
Author
Owner

[P1] A variable declaration is lowered only through its initializer, so expressions in variably modified array bounds are skipped. For int a[bound()], this loses both the call to bound and any identifier uses in the bound, making the call graph and lineage facts incomplete for valid C. Please lower all evaluated declaration expressions, including VLA bounds, while still distinguishing the initializer value.

[P1] A variable declaration is lowered only through its initializer, so expressions in variably modified array bounds are skipped. For `int a[bound()]`, this loses both the call to `bound` and any identifier uses in the bound, making the call graph and lineage facts incomplete for valid C. Please lower all evaluated declaration expressions, including VLA bounds, while still distinguishing the initializer value.
Fix declaration expression semantics
All checks were successful
Validate / Formatting, linting, and tests (push) Successful in 2m26s
Validate / Formatting, linting, and tests (pull_request) Successful in 2m7s
962b47bd94
Author
Owner

Review comment #931: Fixed in 962b47b. Block-scope static initializers are now translation-unit-owned static-storage operations and skipped by callable CFG lowering; IR validation accepts static-local targets while retaining automatic-local rejection. Focused IR/C-facts tests, full tests, rustdoc, and Windows GNU checks passed.

Review comment #931: Fixed in 962b47b. Block-scope static initializers are now translation-unit-owned static-storage operations and skipped by callable CFG lowering; IR validation accepts static-local targets while retaining automatic-local rejection. Focused IR/C-facts tests, full tests, rustdoc, and Windows GNU checks passed.
Author
Owner

Review comment #929: Fixed in 962b47b. Evaluated VLA bounds are lowered before initializers for locals, block typedefs, pointer/multidimensional VLAs, and definition parameters, while prototypes and constant arrays remain non-executable. The C-facts regression and complete 101-unit/5-integration suite passed.

Review comment #929: Fixed in 962b47b. Evaluated VLA bounds are lowered before initializers for locals, block typedefs, pointer/multidimensional VLAs, and definition parameters, while prototypes and constant arrays remain non-executable. The C-facts regression and complete 101-unit/5-integration suite passed.
JayKobe6k changed target branch from issue-6-project-sources to main 2026-09-04 00:50:17 +00:00
Sign in to join this conversation.
No description provided.