Skip to content

[llvm-cov] Fix branch counts of template functions (second attempt) #135074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

stma247
Copy link
Contributor

@stma247 stma247 commented Apr 9, 2025

This PR is a second attempt for issue #111743 to finish reverted PR #113925.

Test run with EXPENSIVE_CHECKS showed a flaky test. It is related to "llvm::sort" that applies some kind of shuffle if expensive checks are on (see https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/STLExtras.h#L1676).
The reason why this issue came up with my initial PR, is that no test for this template ambiguity existed before (see new llvm/test/tools/llvm-cov/branch-export-lcov-unify-instances.test). I can see this indeterministic behavior even on branch "main", if I add test code from "branch-export-lcov-unify-instances.test".

Copy link

github-actions bot commented Apr 9, 2025

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

@stma247
Copy link
Contributor Author

stma247 commented Apr 11, 2025

Ping

@evodius96
Copy link
Contributor

Hi! SOrry for the delay. Can you explain how you get around the non-deterministic behavior? The changes seem OK to me but I want to make sure I'm not overlooking the actual difference.

@stma247 stma247 force-pushed the users/stma247/llvm_cov_export_with_unified_function_instantiations2 branch from e334044 to efbc47a Compare April 17, 2025 14:52
@stma247
Copy link
Contributor Author

stma247 commented Apr 17, 2025

The key is to add an additional field "NestedCountedRegion::Position" which is used by function "sortNested" when ambiguous entries are contained in collections such as "Branches". Such entries may appear whenever a template function with more than one instantiation occurs (then all fields of NestedCountedRegion and it's base classes contain equal values). The field "Position" makes every entry unique and the shuffle of "llvm::sort" has no bad impact on the result.

This problem existed even without my changes, but the new test "branch-export-lcov-unify-instances.test" brought it to light as it does more pedantic checks than the existing template tests.

@evodius96
Copy link
Contributor

Thank you! Looks good to me. Let me know if you need assistance merging again.

stma247 added 2 commits April 22, 2025 13:17
Added option "--unify-instantiations" to llvm-cov export to combine
branch execution counts of C++ template instantiations.

on-behalf-of: @e-solutions-GmbH <info@esolutions.de>
Fixed flaky test if EXPENSIVE_CHECKS are enabled, caused by an ambiguous comparator.
Keep orginal position in NestedCountedRegion to sort distinct.

on-behalf-of: @e-solutions-GmbH <info@esolutions.de>
@stma247 stma247 force-pushed the users/stma247/llvm_cov_export_with_unified_function_instantiations2 branch from 169d8fb to 82382d3 Compare April 22, 2025 11:18
@stma247
Copy link
Contributor Author

stma247 commented Apr 22, 2025

Yes please, I haven't requested write access so far.
Thanks in advance.

@evodius96 evodius96 merged commit 72b2d4d into llvm:main Apr 24, 2025
11 checks passed
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…lvm#135074)

This PR is a second attempt for issue llvm#111743 to finish reverted PR
llvm#113925.

Added option "--unify-instantiations" to llvm-cov export to combine branch execution counts of C++ template instantiations.  Fix non-deterministic behavior.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…lvm#135074)

This PR is a second attempt for issue llvm#111743 to finish reverted PR
llvm#113925.

Added option "--unify-instantiations" to llvm-cov export to combine branch execution counts of C++ template instantiations.  Fix non-deterministic behavior.
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
…lvm#135074)

This PR is a second attempt for issue llvm#111743 to finish reverted PR
llvm#113925.

Added option "--unify-instantiations" to llvm-cov export to combine branch execution counts of C++ template instantiations.  Fix non-deterministic behavior.
Ankur-0429 pushed a commit to Ankur-0429/llvm-project that referenced this pull request May 9, 2025
…lvm#135074)

This PR is a second attempt for issue llvm#111743 to finish reverted PR
llvm#113925.

Added option "--unify-instantiations" to llvm-cov export to combine branch execution counts of C++ template instantiations.  Fix non-deterministic behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants