Update for Code Coverage, Fixing Double Counts on Functions Compiled in Different Binaries and Merging of Conditional Compilation #151771
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.
The following PR is addressing these two issues:
#148279
#148673
The current state of code coverage in llvm had two bugs that occurred when merging .profraw files. Issue 148279 occurred because of the way that llvm-profdata would map functions to their respective counter values. These mappings work by using the function name and the function control flow hash to map to their counters. So, if two functions with the same name and the same control flow appear in the .profraw files, their counters will be merged. My changes address this issue by using the object file along with the function name and the function control flow hash to map to the counters. This way, binaries compiled with the same function in different binaries can be differentiated. You can see the effect of this by using the --object-aware-hashing flag implemented in llvm-profdata, and the --merge-binary-coverage flag in llvm-cov.
Example workflow:
the llvm-lit test case "merge-same-func-diff-bin.c" located where the llvm-cov tests exist, tests if the double counts on main appear on the example shown in issue 148279.
This same workflow also addresses the conditional compilation problems in issue 148673. The reason this issue occurred was because of the way llvm-profdata created the hash values that mapped to the counters (as explained above) and because of the duplication checks in llvm-cov. If llvm-cov sees that a particular function name has already been processed, it will skip any other mentions of that particular function. So with my changes, if a function has been processed, it will merge the execution counts and any new regions that appear into the list of Regions that is held by the first instance of the function processed. Later this combined list of Regions is then processed so that the right counts show up on any Regions that were incorrectly labeled as a "Skipped Region" during the conditional compilation. The llvm-lit test case "merge-binary-coverage.c" will test for the right counts in a conditional compilation.
Lastly, these updates also add the --show-arch-executables flag in llvm-cov, which will allow the user to see the merged function coverage, along with the specific coverage from each executable. These sub-views will list the particular object file the coverage is refering too along with the architecture of the object file. The llvm-lit test case "merge-show-arch-exec.c" does a simple test of this feature.
Example of using --show-arch-executables:
@quic-akaryaki
@quic-areg
@quic-seaswara
@evodius96
@chapuni