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

-Zcoverage is unimplemented #1494

Open
weiznich opened this issue Jun 4, 2024 · 6 comments
Open

-Zcoverage is unimplemented #1494

weiznich opened this issue Jun 4, 2024 · 6 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@weiznich
Copy link

weiznich commented Jun 4, 2024

I've tried to use the cranlift rust backend for a project that records code coverage for tests. For this I run the following command:

RUSTFLAGS="-Zcodegen-backend=cranelift" cargo +nightly llvm-cov test -j 1

which resulted in the following error:

   Compiling proc-macro2 v1.0.78
error: -Zcoverage is unimplemented

stmt Coverage::CounterIncrement(0)
fn main() -> () {
    let mut _0: ();
// … more MIR 

I expected that this would likely not work. I was just surprised that there is no issue for this yet, so I filled that one.

@bjorn3
Copy link
Member

bjorn3 commented Jun 4, 2024

LLVM's coverage infrastructure is LLVM specific and the exact data format even changes between LLVM versions.

https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#format-compatibility-guarantees

There are no backwards or forwards compatibility guarantees for the raw profile format. Raw profiles may be dependent on the specific compiler revision used to generate them. It’s inadvisable to store raw profiles for long periods of time.

Implementing coverage support in cg_clif would be possible, but it will not be compatible with llvm-cov. And it will require writing a replacement for the LLVM profiler runtime and getting rustc to use this replacement.

@bjorn3 bjorn3 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 4, 2024
@weiznich
Copy link
Author

weiznich commented Jun 4, 2024

Thanks for your response. As already written before I did not expect this to work.

I think the problematic part here is that -Ccoverage is a option that's supported by a stable compiler, which somewhat makes this format/option more official from my point of view.

Maybe a short term solution would be to just change the message so that it does not say anymore that it's unimplemented but not supported or something like that? Maybe even with a bit more context outlining that this is a llvm specific feature?

@bjorn3
Copy link
Member

bjorn3 commented Jun 4, 2024

-Cllvm-args is also supported on stable, yet we don't guarantee anything about it either. We can't anyway as LLVM doesn't make any stability promises about which flags it supports. (Clang flags don't always directly map to LLVM flags and some LLVM flags are not exposed by clang at all.)

Maybe a short term solution would be to just change the message so that it does not say anymore that it's unimplemented but not supported or something like that? Maybe even with a bit more context outlining that this is a llvm specific feature?

Done

@weiznich
Copy link
Author

I just stumbled on https://crates.io/crates/minicov which seem to implement most of the necessary format. It seems like that crate could be used to generate the relevant glue code to support this flag?

@bjorn3
Copy link
Member

bjorn3 commented Aug 27, 2024

Profiling support is split into two parts: an instrumentation pass in the compiler and a profiler runtime. Cg_clif misses the instrumentation pass, while minicov implements the profiler runtime. I am pretty sure cg_clif can reuse the LLVM profiler runtime in the profiler-builtins crate already, so using minicov doesn't really help here. Once the instrumentation pass is written for cg_clif, profiler-builtins and minicov could be used interchangably.

@weiznich
Copy link
Author

Thanks for the clarification. To be honest it sounded already a bit too easy in the beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

2 participants