Repository navigation
fix(diagnostics): report a header function's diagnostics in its header - #195
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.cppset no file, andanalyzeFilethen spelled the empty path as the analyzed input.Fix
At the end of
AnalysisPipeline::run,assignFunctionFilesToDiagnosticsgives 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 asIntegerOverflow'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
check_header_function_diagnostics_name_the_headercovers a template, an inline function and a static C function. It compares full paths and lines. It fails onmainin 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.--compile-ir-cache-dir, unit tests included): 2384/2384 on macOS and on Linux x86_64.Before / after (
maindaaf4cd vs this branch, Linux x86_64)defaultandz3configurations: 846 runs, 0 differ, 1287 = 1287 diagnostics.InstructionSubscriberRegistry::add:src/analyzer/AnalysisPipeline.cpp:37->include/analyzer/InstructionSubscriber.hpp:37runCrossTUSummaryPass, both instances:src/app/AnalyzerApp.cpp:217->src/app/CrossTUSummaryDriver.hpp:217Limits
always_inlinefunction was checked, but the analyzer saw it uninlined, so that case is not proven.Code scanning
CI is green on 10d4695: 13 checks pass, the release attach step is skipped.
main. Nogithub-advanced-securitycomment on this PR. No newcoretrace-concurrency-analyzeralert.mainaremainalerts moved by this fix to the header of their function. Each pair has the same rule and the same message:ConstParameterNotModified.Reference,InstructionSubscriberRegistry::add):src/analyzer/AnalysisPipeline.cpp:37->include/analyzer/InstructionSubscriber.hpp:37ConstParameterNotModified.ReferenceRvaluePreferValue, both instances ofrunCrossTUSummaryPass):src/app/AnalyzerApp.cpp:217->src/app/CrossTUSummaryDriver.hpp:217AnalyzerApp.cpp.