Skip to content

fix(diagnostics): report a header function's diagnostics in its header - #195

Merged
SizzleUnrlsd merged 2 commits into
mainfrom
174-header-diagnostic-file
Oct 8, 2026
Merged

SizzleUnrlsd merged 2 commits into
mainfrom
174-header-diagnostic-file

Conversation

@SizzleUnrlsd

@SizzleUnrlsd SizzleUnrlsd commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #174

Problem

A diagnostic in a function defined in a header was reported in the file that includes the header, at the line it has in the header. 13 of the 22 diagnostic builders in DiagnosticEmitter.cpp set no file, and analyzeFile then spelled the empty path as the analyzed input.

Fix

At the end of AnalysisPipeline::run, assignFunctionFilesToDiagnostics gives each diagnostic without a file the file of its function, found by its LLVM name. LLVM names are unique in a module, so overloads and template instances are told apart. A file that a rule already set is kept, so locations such as IntegerOverflow's are unchanged. This covers the library API (analyzeModule) and the CLI. A diagnostic with no known function still falls back to the analyzed input.

Tests

  • New check check_header_function_diagnostics_name_the_header covers a template, an inline function and a static C function. It compares full paths and lines. It fails on main in all 3 cases and passes with the fix.
  • check_diagnostic_paths_follow_the_input (fix(report): spell every result's file as the input was given #124) passes before and after.
  • CI-like suite (--compile-ir-cache-dir, unit tests included): 2384/2384 on macOS and on Linux x86_64.

Before / after (main daaf4cd vs this branch, Linux x86_64)

  • Fixtures, default and z3 configurations: 846 runs, 0 differ, 1287 = 1287 diagnostics.
  • Self-analysis, 4 chunks: 71 = 71 diagnostics. 3 diagnostics move to the header of their function, at the same line:
    • InstructionSubscriberRegistry::add: src/analyzer/AnalysisPipeline.cpp:37 -> include/analyzer/InstructionSubscriber.hpp:37
    • runCrossTUSummaryPass, both instances: src/app/AnalyzerApp.cpp:217 -> src/app/CrossTUSummaryDriver.hpp:217

Limits

  • The function's file is a fallback. An instruction that is really inlined from another file would need its own LLVM debug location. A header always_inline function was checked, but the analyzer saw it uninlined, so that case is not proven.
  • No test covers keeping a file a rule already set: today every rule that sets a file sets its function's file.
  • Moving the 3 self-analysis results may close their code-scanning alerts and reopen them under new numbers. Triage will follow once CI has run.

Code scanning

CI is green on 10d4695: 13 checks pass, the release attach step is skipped.

A diagnostic in a function defined in a header is reported in the file
that includes it, at the line it has in the header, when its rule does
not set a file itself (#174). Cover a template, an inline function and a
static C function, and compare full paths.
A rule that locates a diagnostic without naming its file left it empty,
and analyzeFile then spelled it as the analyzed input. A diagnostic in a
function defined in a header was therefore reported in the including
file, at the line it has in the header.

At the end of the pipeline, give such a diagnostic the file of its
function, found by its LLVM name. A file a rule already named is kept.

Fixes #174
@SizzleUnrlsd SizzleUnrlsd added the bug Something isn't working label Oct 8, 2026
@SizzleUnrlsd SizzleUnrlsd self-assigned this Oct 8, 2026
@SizzleUnrlsd
SizzleUnrlsd merged commit db0c4fe into main Oct 8, 2026
14 checks passed
@SizzleUnrlsd
SizzleUnrlsd deleted the 174-header-diagnostic-file branch October 8, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diagnostics in a function defined in a header are reported in the file that includes it

1 participant