Skip to content

Commit bdf9ed4

Browse files
authored
Rollup merge of rust-lang#111878 - ferrocene:pa-codegen-tests, r=Mark-Simulacrum
Fix codegen test suite for bare-metal-like targets For Ferrocene I needed to run the test suite for custom target with no unwinding and static relocation. Running the tests uncovered ~20 failures due to the test suite not accounting for these options. This PR fixes them by: * Fixing `CHECK`s to account for functions having extra LLVM IR attributes (in this case `nounwind`). * Fixing `CHECK`s to account for the `dso_local` LLVM IR modifier, which is [added to every item when relocation is static](https://github.com/rust-lang/rust/blob/f3d597b31c0f101a02c230798afa31a36bdacbc6/compiler/rustc_codegen_llvm/src/mono_item.rs#L139-L142). * Fixing `CHECK`s to account for missing `uwtables` attributes. * Added the `needs-unwind` attributes for tests that are designed to check unwinding. There is no part of Rust CI that checks this unfortunately, and testing whether the PR works locally is kinda hard because you need a target with std enabled but no unwinding and static relocations. Still, this works in my local testing, and if future PRs accidentally break this Ferrocene will take care of sending followup PRs.
2 parents 6e024ec + 5f0b677 commit bdf9ed4

21 files changed

+64
-55
lines changed

tests/codegen/box-maybe-uninit-llvm14.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
3131
// Hide the LLVM 15+ `allocalign` attribute in the declaration of __rust_alloc
3232
// from the CHECK-NOT above. We don't check the attributes here because we can't rely
3333
// on all of them being set until LLVM 15.
34-
// CHECK: declare noalias{{.*}} @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+.*}} noundef)
34+
// CHECK: declare {{(dso_local )?}}noalias{{.*}} @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+.*}} noundef)

tests/codegen/box-maybe-uninit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ pub fn box_uninitialized2() -> Box<MaybeUninit<[usize; 1024 * 1024]>> {
2828

2929
// Hide the `allocalign` attribute in the declaration of __rust_alloc
3030
// from the CHECK-NOT above, and also verify the attributes got set reasonably.
31-
// CHECK: declare noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]]
31+
// CHECK: declare {{(dso_local )?}}noalias noundef ptr @__rust_alloc(i{{[0-9]+}} noundef, i{{[0-9]+}} allocalign noundef) unnamed_addr [[RUST_ALLOC_ATTRS:#[0-9]+]]
3232

33-
// CHECK-DAG: attributes [[RUST_ALLOC_ATTRS]] = { {{.*}} allockind("alloc,uninitialized,aligned") allocsize(0) uwtable "alloc-family"="__rust_alloc" {{.*}} }
33+
// CHECK-DAG: attributes [[RUST_ALLOC_ATTRS]] = { {{.*}} allockind("alloc,uninitialized,aligned") allocsize(0) {{(uwtable )?}}"alloc-family"="__rust_alloc" {{.*}} }

tests/codegen/call-metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#![crate_type = "lib"]
77

88
pub fn test() {
9-
// CHECK: call noundef i8 @some_true(), !range [[R0:![0-9]+]]
9+
// CHECK: call noundef i8 @some_true(){{( #[0-9]+)?}}, !range [[R0:![0-9]+]]
1010
// CHECK: [[R0]] = !{i8 0, i8 3}
1111
some_true();
1212
}

tests/codegen/debug-column.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
fn main() {
77
unsafe {
88
// Column numbers are 1-based. Regression test for #65437.
9-
// CHECK: call void @giraffe(), !dbg [[A:!.*]]
9+
// CHECK: call void @giraffe(){{( #[0-9]+)?}}, !dbg [[A:!.*]]
1010
giraffe();
1111

1212
// Column numbers use byte offests. Regression test for #67360
13-
// CHECK: call void @turtle(), !dbg [[B:!.*]]
13+
// CHECK: call void @turtle(){{( #[0-9]+)?}}, !dbg [[B:!.*]]
1414
/* ż */ turtle();
1515

1616
// CHECK: [[A]] = !DILocation(line: 10, column: 9,

tests/codegen/drop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// ignore-wasm32-bare compiled with panic=abort by default
2+
// needs-unwind - this test verifies the amount of drop calls when unwinding is used
23
// compile-flags: -C no-prepopulate-passes
34

45
#![crate_type = "lib"]

tests/codegen/external-no-mangle-statics.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,72 @@
66
// `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their
77
// definitions
88

9-
// CHECK: @A = local_unnamed_addr constant
9+
// CHECK: @A = {{(dso_local )?}}local_unnamed_addr constant
1010
#[no_mangle]
1111
static A: u8 = 0;
1212

13-
// CHECK: @B = local_unnamed_addr global
13+
// CHECK: @B = {{(dso_local )?}}local_unnamed_addr global
1414
#[no_mangle]
1515
static mut B: u8 = 0;
1616

17-
// CHECK: @C = local_unnamed_addr constant
17+
// CHECK: @C = {{(dso_local )?}}local_unnamed_addr constant
1818
#[no_mangle]
1919
pub static C: u8 = 0;
2020

21-
// CHECK: @D = local_unnamed_addr global
21+
// CHECK: @D = {{(dso_local )?}}local_unnamed_addr global
2222
#[no_mangle]
2323
pub static mut D: u8 = 0;
2424

2525
mod private {
26-
// CHECK: @E = local_unnamed_addr constant
26+
// CHECK: @E = {{(dso_local )?}}local_unnamed_addr constant
2727
#[no_mangle]
2828
static E: u8 = 0;
2929

30-
// CHECK: @F = local_unnamed_addr global
30+
// CHECK: @F = {{(dso_local )?}}local_unnamed_addr global
3131
#[no_mangle]
3232
static mut F: u8 = 0;
3333

34-
// CHECK: @G = local_unnamed_addr constant
34+
// CHECK: @G = {{(dso_local )?}}local_unnamed_addr constant
3535
#[no_mangle]
3636
pub static G: u8 = 0;
3737

38-
// CHECK: @H = local_unnamed_addr global
38+
// CHECK: @H = {{(dso_local )?}}local_unnamed_addr global
3939
#[no_mangle]
4040
pub static mut H: u8 = 0;
4141
}
4242

4343
const HIDDEN: () = {
44-
// CHECK: @I = local_unnamed_addr constant
44+
// CHECK: @I = {{(dso_local )?}}local_unnamed_addr constant
4545
#[no_mangle]
4646
static I: u8 = 0;
4747

48-
// CHECK: @J = local_unnamed_addr global
48+
// CHECK: @J = {{(dso_local )?}}local_unnamed_addr global
4949
#[no_mangle]
5050
static mut J: u8 = 0;
5151

52-
// CHECK: @K = local_unnamed_addr constant
52+
// CHECK: @K = {{(dso_local )?}}local_unnamed_addr constant
5353
#[no_mangle]
5454
pub static K: u8 = 0;
5555

56-
// CHECK: @L = local_unnamed_addr global
56+
// CHECK: @L = {{(dso_local )?}}local_unnamed_addr global
5757
#[no_mangle]
5858
pub static mut L: u8 = 0;
5959
};
6060

6161
fn x() {
62-
// CHECK: @M = local_unnamed_addr constant
62+
// CHECK: @M = {{(dso_local )?}}local_unnamed_addr constant
6363
#[no_mangle]
6464
static M: fn() = x;
6565

66-
// CHECK: @N = local_unnamed_addr global
66+
// CHECK: @N = {{(dso_local )?}}local_unnamed_addr global
6767
#[no_mangle]
6868
static mut N: u8 = 0;
6969

70-
// CHECK: @O = local_unnamed_addr constant
70+
// CHECK: @O = {{(dso_local )?}}local_unnamed_addr constant
7171
#[no_mangle]
7272
pub static O: u8 = 0;
7373

74-
// CHECK: @P = local_unnamed_addr global
74+
// CHECK: @P = {{(dso_local )?}}local_unnamed_addr global
7575
#[no_mangle]
7676
pub static mut P: u8 = 0;
7777
}

tests/codegen/issues/issue-86106.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#![crate_type = "lib"]
99

10-
// CHECK-LABEL: define void @string_new
10+
// CHECK-LABEL: define {{(dso_local )?}}void @string_new
1111
#[no_mangle]
1212
pub fn string_new() -> String {
1313
// CHECK: store ptr inttoptr
@@ -17,7 +17,7 @@ pub fn string_new() -> String {
1717
String::new()
1818
}
1919

20-
// CHECK-LABEL: define void @empty_to_string
20+
// CHECK-LABEL: define {{(dso_local )?}}void @empty_to_string
2121
#[no_mangle]
2222
pub fn empty_to_string() -> String {
2323
// CHECK: store ptr inttoptr

tests/codegen/link_section.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#![crate_type = "lib"]
55

6-
// CHECK: @VAR1 = constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one"
6+
// CHECK: @VAR1 = {{(dso_local )?}}constant <{ [4 x i8] }> <{ [4 x i8] c"\01\00\00\00" }>, section ".test_one"
77
#[no_mangle]
88
#[link_section = ".test_one"]
99
#[cfg(target_endian = "little")]
@@ -19,17 +19,17 @@ pub enum E {
1919
B(f32)
2020
}
2121

22-
// CHECK: @VAR2 = constant {{.*}}, section ".test_two"
22+
// CHECK: @VAR2 = {{(dso_local )?}}constant {{.*}}, section ".test_two"
2323
#[no_mangle]
2424
#[link_section = ".test_two"]
2525
pub static VAR2: E = E::A(666);
2626

27-
// CHECK: @VAR3 = constant {{.*}}, section ".test_three"
27+
// CHECK: @VAR3 = {{(dso_local )?}}constant {{.*}}, section ".test_three"
2828
#[no_mangle]
2929
#[link_section = ".test_three"]
3030
pub static VAR3: E = E::B(1.);
3131

32-
// CHECK: define void @fn1() {{.*}} section ".test_four" {
32+
// CHECK: define {{(dso_local )?}}void @fn1() {{.*}} section ".test_four" {
3333
#[no_mangle]
3434
#[link_section = ".test_four"]
3535
pub fn fn1() {}

tests/codegen/mir-inlined-line-numbers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn example() {
1919
}
2020

2121
// CHECK-LABEL: @example
22-
// CHECK: tail call void @bar(), !dbg [[DBG_ID:![0-9]+]]
22+
// CHECK: tail call void @bar(){{( #[0-9]+)?}}, !dbg [[DBG_ID:![0-9]+]]
2323
// CHECK: [[DBG_ID]] = !DILocation(line: 7,
2424
// CHECK-SAME: inlinedAt: [[INLINE_ID:![0-9]+]])
2525
// CHECK: [[INLINE_ID]] = !DILocation(line: 18,

tests/codegen/naked-noinline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::arch::asm;
1212
pub unsafe extern "C" fn f() {
1313
// Check that f has naked and noinline attributes.
1414
//
15-
// CHECK: define void @f() unnamed_addr [[ATTR:#[0-9]+]]
15+
// CHECK: define {{(dso_local )?}}void @f() unnamed_addr [[ATTR:#[0-9]+]]
1616
// CHECK-NEXT: start:
1717
// CHECK-NEXT: call void asm
1818
asm!("", options(noreturn));
@@ -22,7 +22,7 @@ pub unsafe extern "C" fn f() {
2222
pub unsafe fn g() {
2323
// Check that call to f is not inlined.
2424
//
25-
// CHECK-LABEL: define void @g()
25+
// CHECK-LABEL: define {{(dso_local )?}}void @g()
2626
// CHECK-NEXT: start:
2727
// CHECK-NEXT: call void @f()
2828
f();

0 commit comments

Comments
 (0)