Open loynoir opened 2 months ago
Hey there @loynoir
Can you also provide the command and arguments that are run inside of yarn test:coverage
? Also any RUSTFLAGS you might have set?
I can't reproduce it when running when running cargo llvm-cov
with nightly-2024-08-27
@ranger-ross
I follow coverage document with doctest support
https://doc.rust-lang.org/rustc/instrument-coverage.html
Something like below
env \
RUSTFLAGS='-C instrument-coverage' \
RUSTDOCFLAGS='-C instrument-coverage -Z unstable-options --persist-doctests /path/to/doctestbins' \
LLVM_PROFILE_FILE="/path/to/profraw/cargo-test-%p-%9m.profraw" \
cargo test --verbose --profile release
# TODO
OBJS=(
# -object /path/to/target/xxx/deps/xxx
# -object /path/to/target/xxx/deps/xxx
# -object /path/to/target/xxx/deps/xxx
# -object /path/to/doctestbins/*/rust_out
)
D="$(rustc --print sysroot)"/lib/rustlib/x86_64-unknown-linux-gnu/bin
"$D"/llvm-profdata merge -sparse -o /path/to/profdata /path/to/profraw/
"$D"/llvm-cov show --format html \
--output-dir /path/to/html \
--ignore-filename-regex=/.cargo/registry \
--ignore-filename-regex=/rustc/ \
--instr-profile /path/to/profdata \
"${OBJS[@]}" \
--show-instantiations \
--show-line-counts-or-regions \
--Xdemangler="${HOME}"/.cargo/bin/rustfilt
@loynoir I spent some more time trying to reproduce the issue, but unfortunately wasn't able to.
I tried with a few different version of nightly before and after nightly-2024-08-27
.
I pushed up my testing code to https://github.com/ranger-ross/rust-130065
When I run ./crate-b/test.sh
the report the HTML report is generated properly.
I also find out I cannot reproduce this from scratch.
I will find a time to extract the reproduce logic out from workspace.
Maybe there is something within workspace but not mentioned above.
Hi @ranger-ross , I can reproduce using https://github.com/loynoir/reproduce-rust-130065
Hi @ranger-ross , I tested able to reproduce from scratch using docker with ubuntu image.
I spent some time debugging this and this issue appears to have been introduced in nightly-2024-02-25
and is not an issue on nightly-2024-02-24
and below. (commits between them)
Unfortunately, finding the issue is a bit beyond my abilities/knowledge of how the compiler instruments the LLVM IR :sweat_smile:
@rustbot label +A-code-coverage +A-codegen +T-compiler +S-has-mcve +requires-nightly -needs-triage
Also I have noticed that, its not just comments. Replacing the comment with another import like use std::sync::Arc;
also causes the issue for me.
When I want to suppress this warning as workaround, another thing I found is, seems like llvm-cov
report suppress warning when stderr is not terminal.
{
llvm-cov export ...
} 2> <(cat)
I did some more debugging this weekend and the LLVM IR seemingly appears to be correct. I haven't looked into the llvm-cov implementation but I think it could possibly be related to https://github.com/llvm/llvm-project/issues/72786
bug
llvm-cov
warning: 1 functions have mismatched data
caused by comment linebackground
Found
llvm-cov
warning: N functions have mismatched data
.After debug, very suprisingly find out this may all caused by comment line.
actual
llvm-cov
warning: 1 functions have mismatched data
caused by comment line// foo
crate A
crate B
expected
comment line
// foo
should not lead tollvm-cov
warning: 1 functions have mismatched data
crate A remove comment line
version