Skip to content

[BUG] llvm-cov warning mismatched data when double slash comment above use #130065

Open
@loynoir

Description

bug

llvm-cov warning: 1 functions have mismatched data caused by comment line

background

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

#![feature(str_from_raw_parts)]

// foo
use core::str::from_raw_parts;

/// # Safety
///
/// TODO
#[inline]
#[must_use]
pub const unsafe fn str_from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str {
    from_raw_parts(ptr, len)
}

crate B

    use feature_str_from_raw_parts_util::str_from_raw_parts;

    #[test]
    fn should_ok() {
        let x = unsafe { str_from_raw_parts("foobar".as_ptr(), 3) };
        let _ = x;
$ yarn cleanup:everything && yarn test:coverage
...
+ /path/to/llvm-cov report ...
warning: 1 functions have mismatched data
...

expected

comment line // foo should not lead to llvm-cov warning: 1 functions have mismatched data

crate A remove comment line

#![feature(str_from_raw_parts)]

use core::str::from_raw_parts;

/// # Safety
///
/// TODO
#[inline]
#[must_use]
pub const unsafe fn str_from_raw_parts<'a>(ptr: *const u8, len: usize) -> &'a str {
    from_raw_parts(ptr, len)
}
$ yarn cleanup:everything && yarn test:coverage
...
(llvm-cov no warning)
...

version

rustc 1.82.0-nightly (1f12b9b0f 2024-08-27)
binary: rustc
commit-hash: 1f12b9b0fdbe735968ac002792a720f0ba4faca6
commit-date: 2024-08-27
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Activity

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

Metadata

Assignees

No one assigned

    Labels

    A-code-coverageArea: Source-based code coverage (-Cinstrument-coverage)A-codegenArea: Code generationC-bugCategory: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions