Skip to content
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

llvm-cov: Instantiation groups are printed in non-deterministic order #62508

Open
Zalathar opened this issue May 3, 2023 · 3 comments
Open

Comments

@Zalathar
Copy link

Zalathar commented May 3, 2023

When llvm-cov show shows instantiation groups, it seems to print them in a non-deterministic order (presumably influenced by hash bucket order).

This is a hassle for Rust's -Cinstrument-coverage tests, since they have to jump through hoops to ignore instantiation names when comparing output snapshots.

Ideally the instantiations should at least be naïvely sorted by their function name. That would at least be deterministic in the common case where all instantiations have distinct names.

@Zalathar
Copy link
Author

Zalathar commented May 3, 2023

It seems that the instantiations do get sorted for display:

// We need the expansions, instantiations, and branches sorted so we can go
// through them while we iterate lines.
llvm::stable_sort(ExpansionSubViews);
llvm::stable_sort(InstantiationSubViews);
llvm::stable_sort(BranchSubViews);

But this sort only compares their (last) line number so that they display after the correct line, and does not compare the function name for instantiations with the same line:

friend bool operator<(const InstantiationView &LHS,
const InstantiationView &RHS) {
return LHS.Line < RHS.Line;
}

@Zalathar
Copy link
Author

Zalathar commented May 3, 2023

Here's an example of Rust's instrument-coverage tests accidentally being broken, due to a bug in the regex used to ignore instantiation names: rust-lang/rust#110942

@Zalathar
Copy link
Author

Zalathar commented May 3, 2023

Another potential explanation is that llvm-cov is faithfully preserving the order of entries in the binary’s __llvm_covfun section, and those entries are linked in an unpredictable order.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants