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

coverage: llvm-cov expects column numbers to be bytes, not code points #119033

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
coverage: Test for column numbers involving non-ASCII characters
  • Loading branch information
Zalathar committed Jan 8, 2024
commit 585a28561996be51739e9a0523371e6e0339cb56
53 changes: 53 additions & 0 deletions tests/coverage/unicode.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 1,53 @@
Function name: unicode::main
Raw bytes (67): 0x[01, 01, 09, 01, 05, 03, 05, 1e, 0d, 22, 09, 03, 05, 11, 1b, 1e, 0d, 22, 09, 03, 05, 09, 01, 0e, 01, 00, 0b, 05, 01, 09, 00, 0b, 03, 00, 0f, 00, 18, 05, 00, 19, 00, 24, 22, 02, 08, 00, 13, 09, 00, 17, 00, 22, 11, 00, 23, 02, 06, 1b, 02, 06, 00, 07, 17, 02, 05, 01, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 9
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Expression(0, Add), rhs = Counter(1)
- expression 2 operands: lhs = Expression(7, Sub), rhs = Counter(3)
- expression 3 operands: lhs = Expression(8, Sub), rhs = Counter(2)
- expression 4 operands: lhs = Expression(0, Add), rhs = Counter(1)
- expression 5 operands: lhs = Counter(4), rhs = Expression(6, Add)
- expression 6 operands: lhs = Expression(7, Sub), rhs = Counter(3)
- expression 7 operands: lhs = Expression(8, Sub), rhs = Counter(2)
- expression 8 operands: lhs = Expression(0, Add), rhs = Counter(1)
Number of file 0 mappings: 9
- Code(Counter(0)) at (prev 14, 1) to (start 0, 11)
- Code(Counter(1)) at (prev 1, 9) to (start 0, 11)
- Code(Expression(0, Add)) at (prev 0, 15) to (start 0, 24)
= (c0 c1)
- Code(Counter(1)) at (prev 0, 25) to (start 0, 36)
- Code(Expression(8, Sub)) at (prev 2, 8) to (start 0, 19)
= ((c0 c1) - c1)
- Code(Counter(2)) at (prev 0, 23) to (start 0, 34)
- Code(Counter(4)) at (prev 0, 35) to (start 2, 6)
- Code(Expression(6, Add)) at (prev 2, 6) to (start 0, 7)
= ((((c0 c1) - c1) - c2) c3)
- Code(Expression(5, Add)) at (prev 2, 5) to (start 1, 2)
= (c4 ((((c0 c1) - c1) - c2) c3))

Function name: unicode::サビ
Raw bytes (9): 0x[01, 01, 00, 01, 01, 1e, 12, 00, 14]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev 30, 18) to (start 0, 20)

Function name: unicode::他 (unused)
Raw bytes (9): 0x[01, 01, 00, 01, 00, 1e, 15, 00, 1f]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Zero) at (prev 30, 21) to (start 0, 31)

Function name: unicode::申し訳ございません
Raw bytes (9): 0x[01, 01, 00, 01, 01, 18, 01, 02, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev 24, 1) to (start 2, 2)

36 changes: 36 additions & 0 deletions tests/coverage/unicode.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,36 @@
// edition: 2021
// ignore-mode-coverage-run - `llvm-cov` fails due to incorrectly-split UTF-8
// llvm-cov-flags: --use-color

// Check that column numbers are denoted in bytes, so that they don't cause
// `llvm-cov` to fail or emit malformed output.
//
// Note that when `llvm-cov` prints ^ arrows on a subsequent line, it simply
// inserts one space character for each "column", with no understanding of
// Unicode or character widths. So those arrows will tend to be misaligned
// for non-ASCII source code, regardless of whether column numbers are code
// points or bytes.

fn main() {
for _İ in 'А'..='Я' { /* Я */ }

if 申し訳ございません() && 申し訳ございません() {
println!("true");
}

サビ();
}

fn 申し訳ございません() -> bool {
std::hint::black_box(false)
}

macro_rules! macro_that_defines_a_function {
(fn $名:ident () $体:tt) => {
fn $名 () $体 fn 他 () {}
}
}

macro_that_defines_a_function! {
fn サビ() {}
}