Skip to content

Commit d140728

Browse files
authored
Rollup merge of rust-lang#149190 - zachs18:chilly, r=Mark-Simulacrum
Forbid `CHECK: br` and `CHECK-NOT: br` in codegen tests (suggest `br {{.*}}` instead) `// CHECK-NOT: br` is fragile to false positives in mangled symbol names, while `// CHECK-NOT: br {{.*}}` is not. Remove and forbid the former in codegen tests, and suggest the latter. cc rust-lang#149125 (comment) where this caused a CI failure due to a v0 mangled symbol containing `br` in a disambiguator/crate hash/something.
2 parents 18ce051 + 238ef54 commit d140728

14 files changed

+59
-53
lines changed

src/tools/tidy/src/style.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ pub fn check(path: &Path, tidy_ctx: TidyCtx) {
445445
let mut comment_block: Option<(usize, usize)> = None;
446446
let is_test = file.components().any(|c| c.as_os_str() == "tests")
447447
|| file.file_stem().unwrap() == "tests";
448+
let is_codegen_test = is_test && file.components().any(|c| c.as_os_str() == "codegen-llvm");
448449
let is_this_file = file.ends_with(this_file) || this_file.ends_with(file);
449450
let is_test_for_this_file =
450451
is_test && file.parent().unwrap().ends_with(this_file.with_extension(""));
@@ -488,6 +489,11 @@ pub fn check(path: &Path, tidy_ctx: TidyCtx) {
488489
)
489490
}
490491

492+
if is_codegen_test && trimmed.contains("CHECK") && trimmed.ends_with(": br") {
493+
err("`CHECK: br` and `CHECK-NOT: br` in codegen tests are fragile to false \
494+
positives in mangled symbols. Try using `br {{.*}}` instead.")
495+
}
496+
491497
if !under_rustfmt
492498
&& line.chars().count() > max_columns
493499
&& !long_line_is_ok(&extension, is_error_code, max_columns, line)

tests/codegen-llvm/char-ascii-branchless.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,41 @@
77
// CHECK-LABEL: @is_ascii_alphanumeric_char
88
#[no_mangle]
99
pub fn is_ascii_alphanumeric_char(x: char) -> bool {
10-
// CHECK-NOT: br
10+
// CHECK-NOT: br {{.*}}
1111
x.is_ascii_alphanumeric()
1212
}
1313

1414
// CHECK-LABEL: @is_ascii_alphanumeric_u8
1515
#[no_mangle]
1616
pub fn is_ascii_alphanumeric_u8(x: u8) -> bool {
17-
// CHECK-NOT: br
17+
// CHECK-NOT: br {{.*}}
1818
x.is_ascii_alphanumeric()
1919
}
2020

2121
// CHECK-LABEL: @is_ascii_hexdigit_char
2222
#[no_mangle]
2323
pub fn is_ascii_hexdigit_char(x: char) -> bool {
24-
// CHECK-NOT: br
24+
// CHECK-NOT: br {{.*}}
2525
x.is_ascii_hexdigit()
2626
}
2727

2828
// CHECK-LABEL: @is_ascii_hexdigit_u8
2929
#[no_mangle]
3030
pub fn is_ascii_hexdigit_u8(x: u8) -> bool {
31-
// CHECK-NOT: br
31+
// CHECK-NOT: br {{.*}}
3232
x.is_ascii_hexdigit()
3333
}
3434

3535
// CHECK-LABEL: @is_ascii_punctuation_char
3636
#[no_mangle]
3737
pub fn is_ascii_punctuation_char(x: char) -> bool {
38-
// CHECK-NOT: br
38+
// CHECK-NOT: br {{.*}}
3939
x.is_ascii_punctuation()
4040
}
4141

4242
// CHECK-LABEL: @is_ascii_punctuation_u8
4343
#[no_mangle]
4444
pub fn is_ascii_punctuation_u8(x: u8) -> bool {
45-
// CHECK-NOT: br
45+
// CHECK-NOT: br {{.*}}
4646
x.is_ascii_punctuation()
4747
}

tests/codegen-llvm/enum/enum-early-otherwise-branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub enum Enum {
1212
pub fn foo(lhs: &Enum, rhs: &Enum) -> bool {
1313
// CHECK-LABEL: define{{.*}}i1 @foo(
1414
// CHECK-NOT: switch
15-
// CHECK-NOT: br
15+
// CHECK-NOT: br {{.*}}
1616
// CHECK: [[SELECT:%.*]] = select
1717
// CHECK-NEXT: ret i1 [[SELECT]]
1818
// CHECK-NEXT: }

tests/codegen-llvm/issues/cows-dont-have-branches-117763.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// CHECK-LABEL: @branchless_cow_slices
1010
#[no_mangle]
1111
pub fn branchless_cow_slices<'a>(cow: &'a std::borrow::Cow<'a, [u8]>) -> &'a [u8] {
12-
// CHECK-NOT: br
12+
// CHECK-NOT: br {{.*}}
1313
// CHECK-NOT: select
1414
// CHECK-NOT: icmp
1515
// CHECK: ret { ptr, {{i32|i64}} }

tests/codegen-llvm/issues/issue-107681-unwrap_unchecked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::slice::Iter;
1111
#[no_mangle]
1212
pub unsafe fn foo(x: &mut Copied<Iter<'_, u32>>) -> u32 {
1313
// CHECK-LABEL: @foo(
14-
// CHECK-NOT: br
14+
// CHECK-NOT: br {{.*}}
1515
// CHECK-NOT: select
1616
// CHECK: [[RET:%.*]] = load i32, ptr
1717
// CHECK-NEXT: ret i32 [[RET]]

tests/codegen-llvm/issues/issue-108395-branchy-bool-match.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// CHECK-LABEL: @wildcard(
77
#[no_mangle]
88
pub fn wildcard(a: u16, b: u16, v: u16) -> u16 {
9-
// CHECK-NOT: br
9+
// CHECK-NOT: br {{.*}}
1010
match (a == v, b == v) {
1111
(true, false) => 0,
1212
(false, true) => u16::MAX,
@@ -17,7 +17,7 @@ pub fn wildcard(a: u16, b: u16, v: u16) -> u16 {
1717
// CHECK-LABEL: @exhaustive(
1818
#[no_mangle]
1919
pub fn exhaustive(a: u16, b: u16, v: u16) -> u16 {
20-
// CHECK-NOT: br
20+
// CHECK-NOT: br {{.*}}
2121
match (a == v, b == v) {
2222
(true, false) => 0,
2323
(false, true) => u16::MAX,

tests/codegen-llvm/issues/issue-119422.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,65 +19,65 @@ pub fn check_non_null(x: NonNull<u8>) -> bool {
1919
// CHECK-LABEL: @equals_zero_is_false_u8
2020
#[no_mangle]
2121
pub fn equals_zero_is_false_u8(x: NonZero<u8>) -> bool {
22-
// CHECK-NOT: br
22+
// CHECK-NOT: br {{.*}}
2323
// CHECK: ret i1 false
24-
// CHECK-NOT: br
24+
// CHECK-NOT: br {{.*}}
2525
x.get() == 0
2626
}
2727

2828
// CHECK-LABEL: @not_equals_zero_is_true_u8
2929
#[no_mangle]
3030
pub fn not_equals_zero_is_true_u8(x: NonZero<u8>) -> bool {
31-
// CHECK-NOT: br
31+
// CHECK-NOT: br {{.*}}
3232
// CHECK: ret i1 true
33-
// CHECK-NOT: br
33+
// CHECK-NOT: br {{.*}}
3434
x.get() != 0
3535
}
3636

3737
// CHECK-LABEL: @equals_zero_is_false_i8
3838
#[no_mangle]
3939
pub fn equals_zero_is_false_i8(x: NonZero<i8>) -> bool {
40-
// CHECK-NOT: br
40+
// CHECK-NOT: br {{.*}}
4141
// CHECK: ret i1 false
42-
// CHECK-NOT: br
42+
// CHECK-NOT: br {{.*}}
4343
x.get() == 0
4444
}
4545

4646
// CHECK-LABEL: @not_equals_zero_is_true_i8
4747
#[no_mangle]
4848
pub fn not_equals_zero_is_true_i8(x: NonZero<i8>) -> bool {
49-
// CHECK-NOT: br
49+
// CHECK-NOT: br {{.*}}
5050
// CHECK: ret i1 true
51-
// CHECK-NOT: br
51+
// CHECK-NOT: br {{.*}}
5252
x.get() != 0
5353
}
5454

5555
// CHECK-LABEL: @usize_try_from_u32
5656
#[no_mangle]
5757
pub fn usize_try_from_u32(x: NonZero<u32>) -> NonZero<usize> {
58-
// CHECK-NOT: br
58+
// CHECK-NOT: br {{.*}}
5959
// CHECK: zext i32 %{{.*}} to i64
60-
// CHECK-NOT: br
60+
// CHECK-NOT: br {{.*}}
6161
// CHECK: ret i64
6262
x.try_into().unwrap()
6363
}
6464

6565
// CHECK-LABEL: @isize_try_from_i32
6666
#[no_mangle]
6767
pub fn isize_try_from_i32(x: NonZero<i32>) -> NonZero<isize> {
68-
// CHECK-NOT: br
68+
// CHECK-NOT: br {{.*}}
6969
// CHECK: sext i32 %{{.*}} to i64
70-
// CHECK-NOT: br
70+
// CHECK-NOT: br {{.*}}
7171
// CHECK: ret i64
7272
x.try_into().unwrap()
7373
}
7474

7575
// CHECK-LABEL: @u64_from_nonzero_is_not_zero
7676
#[no_mangle]
7777
pub fn u64_from_nonzero_is_not_zero(x: NonZero<u64>) -> bool {
78-
// CHECK-NOT: br
78+
// CHECK-NOT: br {{.*}}
7979
// CHECK: ret i1 false
80-
// CHECK-NOT: br
80+
// CHECK-NOT: br {{.*}}
8181
let v: u64 = x.into();
8282
v == 0
8383
}

tests/codegen-llvm/issues/issue-73258.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ pub enum Foo {
1818
pub unsafe fn issue_73258(ptr: *const Foo) -> Foo {
1919
// CHECK-NOT: icmp
2020
// CHECK-NOT: call
21-
// CHECK-NOT: br
21+
// CHECK-NOT: br {{.*}}
2222
// CHECK-NOT: select
2323

2424
// CHECK: %[[R:.+]] = load i8
2525
// CHECK-SAME: !range !
2626

2727
// CHECK-NOT: icmp
2828
// CHECK-NOT: call
29-
// CHECK-NOT: br
29+
// CHECK-NOT: br {{.*}}
3030
// CHECK-NOT: select
3131

3232
// CHECK: ret i8 %[[R]]
3333

3434
// CHECK-NOT: icmp
3535
// CHECK-NOT: call
36-
// CHECK-NOT: br
36+
// CHECK-NOT: br {{.*}}
3737
// CHECK-NOT: select
3838
let k: Option<Foo> = Some(ptr.read());
3939
return k.unwrap();

tests/codegen-llvm/issues/num-is-digit-to-digit-59352.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// CHECK-LABEL: @num_to_digit_slow
99
#[no_mangle]
1010
pub fn num_to_digit_slow(num: char) -> u32 {
11-
// CHECK-NOT: br
11+
// CHECK-NOT: br {{.*}}
1212
// CHECK-NOT: panic
1313
if num.is_digit(8) { num.to_digit(8).unwrap() } else { 0 }
1414
}

tests/codegen-llvm/iter-repeat-n-trivial-drop.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ impl Drop for NotCopy {
1919
// CHECK-LABEL: @iter_repeat_n_next
2020
pub fn iter_repeat_n_next(it: &mut std::iter::RepeatN<NotCopy>) -> Option<NotCopy> {
2121
// CHECK-NEXT: start:
22-
// CHECK-NOT: br
22+
// CHECK-NOT: br {{.*}}
2323
// CHECK: %[[COUNT:.+]] = load i64
2424
// CHECK-NEXT: %[[COUNT_ZERO:.+]] = icmp eq i64 %[[COUNT]], 0
2525
// CHECK-NEXT: br i1 %[[COUNT_ZERO]], label %[[EMPTY:.+]], label %[[NOT_EMPTY:.+]]
2626

2727
// CHECK: [[NOT_EMPTY]]:
28-
// CHECK-NOT: br
28+
// CHECK-NOT: br {{.*}}
2929
// CHECK: %[[DEC:.+]] = add i64 %[[COUNT]], -1
3030
// CHECK-NEXT: %[[VAL:.+]] = load i16
3131
// CHECK-NEXT: store i64 %[[DEC]]
3232
// CHECK-NEXT: br label %[[EMPTY]]
3333

3434
// CHECK: [[EMPTY]]:
35-
// CHECK-NOT: br
35+
// CHECK-NOT: br {{.*}}
3636
// CHECK: phi i16
3737
// CHECK-SAME: [ %[[VAL]], %[[NOT_EMPTY]] ]
38-
// CHECK-NOT: br
38+
// CHECK-NOT: br {{.*}}
3939
// CHECK: ret
4040

4141
it.next()

0 commit comments

Comments
 (0)