Skip to content

Commit f125538

Browse files
committed
Add more codegen tests
1 parent af23ad9 commit f125538

26 files changed

+166
-139
lines changed

tests/codegen/abi-sysv64.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// of the sysv64 abi.
44
//
55
// needs-llvm-components: x86
6-
// compile-flags: -C no-prepopulate-passes --target=x86_64-unknown-linux-gnu
6+
// compile-flags: -C no-prepopulate-passes --target=x86_64-unknown-linux-gnu -Copt-level=0
77

88
#![crate_type = "lib"]
99
#![no_core]
@@ -15,7 +15,7 @@ trait Sized {}
1515
trait Copy {}
1616
impl Copy for i64 {}
1717

18-
// CHECK: define x86_64_sysvcc noundef i64 @has_sysv64_abi
18+
// CHECK: define x86_64_sysvcc i64 @has_sysv64_abi
1919
#[no_mangle]
2020
pub extern "sysv64" fn has_sysv64_abi(a: i64) -> i64 {
2121
a

tests/codegen/abi-x86-interrupt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// of the x86-interrupt abi.
44

55
// needs-llvm-components: x86
6-
// compile-flags: -C no-prepopulate-passes --target=x86_64-unknown-linux-gnu
6+
// compile-flags: -C no-prepopulate-passes --target=x86_64-unknown-linux-gnu -Copt-level=0
77

88
#![crate_type = "lib"]
99
#![no_core]
@@ -15,7 +15,7 @@ trait Sized {}
1515
trait Copy {}
1616
impl Copy for i64 {}
1717

18-
// CHECK: define x86_intrcc noundef i64 @has_x86_interrupt_abi
18+
// CHECK: define x86_intrcc i64 @has_x86_interrupt_abi
1919
#[no_mangle]
2020
pub extern "x86-interrupt" fn has_x86_interrupt_abi(a: i64) -> i64 {
2121
a

tests/codegen/adjustments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
22

33
#![crate_type = "lib"]
44

55
// Hack to get the correct size for the length part in slices
6-
// CHECK: @helper([[USIZE:i[0-9]+]] noundef %_1)
6+
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
77
#[no_mangle]
88
pub fn helper(_: usize) {
99
}

tests/codegen/c-variadic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-wasm32-bare compiled with panic=abort by default
2-
// compile-flags: -C no-prepopulate-passes
2+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
33
//
44

55
#![crate_type = "lib"]
@@ -15,7 +15,7 @@ extern "C" {
1515

1616
pub unsafe extern "C" fn use_foreign_c_variadic_0() {
1717
// Ensure that we correctly call foreign C-variadic functions.
18-
// CHECK: call void (i32, ...) @foreign_c_variadic_0([[PARAM:i32 noundef( signext)?]] 0)
18+
// CHECK: call void (i32, ...) @foreign_c_variadic_0([[PARAM:i32( signext)?]] 0)
1919
foreign_c_variadic_0(0);
2020
// CHECK: call void (i32, ...) @foreign_c_variadic_0([[PARAM]] 0, [[PARAM]] 42)
2121
foreign_c_variadic_0(0, 42i32);
@@ -61,7 +61,7 @@ pub unsafe extern "C" fn c_variadic(n: i32, mut ap: ...) -> i32 {
6161
// Ensure that we generate the correct `call` signature when calling a Rust
6262
// defined C-variadic.
6363
pub unsafe fn test_c_variadic_call() {
64-
// CHECK: call [[RET:noundef( signext)? i32]] (i32, ...) @c_variadic([[PARAM]] 0)
64+
// CHECK: call [[RET:(signext )?i32]] (i32, ...) @c_variadic([[PARAM]] 0)
6565
c_variadic(0);
6666
// CHECK: call [[RET]] (i32, ...) @c_variadic([[PARAM]] 0, [[PARAM]] 42)
6767
c_variadic(0, 42i32);

tests/codegen/call-llvm-intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
22

33
// ignore-riscv64
44

@@ -23,7 +23,7 @@ pub fn do_call() {
2323

2424
unsafe {
2525
// Ensure that we `call` LLVM intrinsics instead of trying to `invoke` them
26-
// CHECK: call noundef float @llvm.sqrt.f32(float noundef 4.000000e+00
26+
// CHECK: call float @llvm.sqrt.f32(float 4.000000e+00
2727
sqrt(4.0);
2828
}
2929
}

tests/codegen/dllimports/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This test is for *-windows-msvc only.
1+
// This test is for *-windows-msvc only.
22
// only-windows
33
// ignore-gnu
44

@@ -15,10 +15,10 @@ extern crate wrapper;
1515
// CHECK: @static_global1 = external local_unnamed_addr global i32
1616
// CHECK: @static_global2 = external local_unnamed_addr global i32
1717

18-
// CHECK: declare dllimport i32 @dylib_func1(i32)
19-
// CHECK: declare dllimport i32 @dylib_func2(i32)
20-
// CHECK: declare i32 @static_func1(i32)
21-
// CHECK: declare i32 @static_func2(i32)
18+
// CHECK: declare dllimport noundef i32 @dylib_func1(i32 noundef)
19+
// CHECK: declare dllimport noundef i32 @dylib_func2(i32 noundef)
20+
// CHECK: declare noundef i32 @static_func1(i32 noundef)
21+
// CHECK: declare noundef i32 @static_func2(i32 noundef)
2222

2323
#[link(name = "dummy", kind="dylib")]
2424
extern "C" {

tests/codegen/frame-pointer.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: --crate-type=rlib
1+
// compile-flags: --crate-type=rlib -Copt-level=0
22
// revisions: aarch64-apple aarch64-linux force x64-apple x64-linux
33
// [aarch64-apple] needs-llvm-components: aarch64
44
// [aarch64-apple] compile-flags: --target=aarch64-apple-darwin
@@ -20,7 +20,7 @@ trait Copy { }
2020
impl Copy for u32 {}
2121

2222

23-
// CHECK: define noundef i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] {
23+
// CHECK: define i32 @peach{{.*}}[[PEACH_ATTRS:\#[0-9]+]] {
2424
#[no_mangle]
2525
pub fn peach(x: u32) -> u32 {
2626
x

tests/codegen/function-arguments.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// compile-flags: -O -C no-prepopulate-passes
22

33
#![crate_type = "lib"]
4-
#![feature(rustc_attrs)]
54

65
use std::mem::MaybeUninit;
76
use std::num::NonZeroU64;
87
use std::marker::PhantomPinned;
8+
use std::ptr::NonNull;
99

1010
pub struct S {
1111
_field: [i32; 8],
@@ -138,11 +138,27 @@ pub fn indirect_struct(_: S) {
138138
pub fn borrowed_struct(_: &S) {
139139
}
140140

141+
// CHECK: @option_borrow({{i32\*|ptr}} noalias noundef readonly align 4 dereferenceable_or_null(4) %x)
142+
#[no_mangle]
143+
pub fn option_borrow(x: Option<&i32>) {
144+
}
145+
146+
// CHECK: @option_borrow_mut({{i32\*|ptr}} noalias noundef align 4 dereferenceable_or_null(4) %x)
147+
#[no_mangle]
148+
pub fn option_borrow_mut(x: Option<&mut i32>) {
149+
}
150+
141151
// CHECK: @raw_struct({{%S\*|ptr}} noundef %_1)
142152
#[no_mangle]
143153
pub fn raw_struct(_: *const S) {
144154
}
145155

156+
// CHECK: @raw_option_nonnull_struct({{i32\*|ptr}} noundef %_1)
157+
#[no_mangle]
158+
pub fn raw_option_nonnull_struct(_: Option<NonNull<S>>) {
159+
}
160+
161+
146162
// `Box` can get deallocated during execution of the function, so it should
147163
// not get `dereferenceable`.
148164
// CHECK: noundef nonnull align 4 {{i32\*|ptr}} @_box({{i32\*|ptr}} noalias noundef nonnull align 4 %x)
@@ -200,6 +216,16 @@ pub fn str(_: &[u8]) {
200216
pub fn trait_borrow(_: &dyn Drop) {
201217
}
202218

219+
// CHECK: @option_trait_borrow({{i8\*|ptr}} noundef align 1 %x.0, {{i8\*|ptr}} %x.1)
220+
#[no_mangle]
221+
pub fn option_trait_borrow(x: Option<&dyn Drop>) {
222+
}
223+
224+
// CHECK: @option_trait_borrow_mut({{i8\*|ptr}} noundef align 1 %x.0, {{i8\*|ptr}} %x.1)
225+
#[no_mangle]
226+
pub fn option_trait_borrow_mut(x: Option<&mut dyn Drop>) {
227+
}
228+
203229
// CHECK: @trait_raw({{\{\}\*|ptr}} noundef %_1.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
204230
#[no_mangle]
205231
pub fn trait_raw(_: *const dyn Drop) {

tests/codegen/intrinsics/const_eval_select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
22

33
#![crate_type = "lib"]
44
#![feature(const_eval_select)]
@@ -13,6 +13,6 @@ pub fn hi(n: i32) -> i32 { n }
1313

1414
#[no_mangle]
1515
pub unsafe fn hey() {
16-
// CHECK: call noundef i32 @hi(i32
16+
// CHECK: call i32 @hi(i32
1717
const_eval_select((42,), foo, hi);
1818
}

tests/codegen/intrinsics/mask.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
// compile-flags: -Copt-level=0
12
#![crate_type = "lib"]
23
#![feature(core_intrinsics)]
34

45
// CHECK-LABEL: @mask_ptr
5-
// CHECK-SAME: [[WORD:i[0-9]+]] noundef %mask
6+
// CHECK-SAME: [[WORD:i[0-9]+]] %mask
67
#[no_mangle]
78
pub fn mask_ptr(ptr: *const u16, mask: usize) -> *const u16 {
89
// CHECK: call
9-
// CHECK-SAME: @llvm.ptrmask.{{p0|p0i8}}.[[WORD]]({{ptr|i8\*}} {{%ptr|%0}}, [[WORD]] %mask)
10+
// CHECK-SAME: @llvm.ptrmask.{{p0|p0i8}}.[[WORD]]({{ptr|i8\*}} {{%ptr|%1}}, [[WORD]] %mask)
1011
core::intrinsics::ptr_mask(ptr, mask)
1112
}

tests/codegen/issue-32031.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
22

33
#![crate_type = "lib"]
44

55
#[no_mangle]
66
pub struct F32(f32);
77

8-
// CHECK: define{{.*}}float @add_newtype_f32(float noundef %a, float noundef %b)
8+
// CHECK: define{{.*}}float @add_newtype_f32(float %a, float %b)
99
#[inline(never)]
1010
#[no_mangle]
1111
pub fn add_newtype_f32(a: F32, b: F32) -> F32 {
@@ -15,7 +15,7 @@ pub fn add_newtype_f32(a: F32, b: F32) -> F32 {
1515
#[no_mangle]
1616
pub struct F64(f64);
1717

18-
// CHECK: define{{.*}}double @add_newtype_f64(double noundef %a, double noundef %b)
18+
// CHECK: define{{.*}}double @add_newtype_f64(double %a, double %b)
1919
#[inline(never)]
2020
#[no_mangle]
2121
pub fn add_newtype_f64(a: F64, b: F64) -> F64 {

tests/codegen/issue-58881.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
22
//
33
// only-x86_64
44
// ignore-windows
@@ -16,6 +16,6 @@ struct Bar(u64, u64, u64);
1616

1717
// Ensure that emit arguments of the correct type.
1818
pub unsafe fn test_call_variadic() {
19-
// CHECK: call void (i32, ...) @variadic_fn(i32 noundef 0, i8 {{.*}}, {{%Bar\*|ptr}} {{.*}})
19+
// CHECK: call void (i32, ...) @variadic_fn(i32 0, i8 {{.*}}, {{%Bar\*|ptr}} {{.*}})
2020
variadic_fn(0, Foo(0), Bar(0, 0, 0))
2121
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub fn iter_repeat_n_next(it: &mut std::iter::RepeatN<NotCopy>) -> Option<NotCop
4646
#[no_mangle]
4747
// CHECK-LABEL: @vec_extend_via_iter_repeat_n
4848
pub fn vec_extend_via_iter_repeat_n() -> Vec<u8> {
49-
// CHECK: %[[ADDR:.+]] = tail call dereferenceable_or_null(1234) ptr @__rust_alloc(i64 1234, i64 1)
49+
// CHECK: %[[ADDR:.+]] = tail call noundef dereferenceable_or_null(1234) ptr @__rust_alloc(i64 noundef 1234, i64 noundef 1)
5050
// CHECK: tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1234) %[[ADDR]], i8 42, i64 1234,
5151

5252
let n = 1234_usize;

tests/codegen/loads.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn load_scalar_pair<'a>(x: &(&'a i32, &'a Align16)) -> (&'a i32, &'a Align16
5151
#[no_mangle]
5252
pub fn load_raw_pointer<'a>(x: &*const i32) -> *const i32 {
5353
// loaded raw pointer should not have !nonnull or !align metadata
54-
// CHECK: load {{i32\*|ptr}}, {{i32\*\*|ptr}} %x, align [[PTR_ALIGNMENT]], !noundef !2{{$}}
54+
// CHECK: load {{i32\*|ptr}}, {{i32\*\*|ptr}} %x, align [[PTR_ALIGNMENT]], !noundef ![[NOUNDEF:[0-9]+]]{{$}}
5555
*x
5656
}
5757

@@ -93,7 +93,7 @@ pub fn load_maybeuninit_enum_bool(x: &MaybeUninit<MyBool>) -> MaybeUninit<MyBool
9393
// CHECK-LABEL: @load_int
9494
#[no_mangle]
9595
pub fn load_int(x: &u16) -> u16 {
96-
// CHECK: load i16, {{i16\*|ptr}} %x, align 2, !noundef !2{{$}}
96+
// CHECK: load i16, {{i16\*|ptr}} %x, align 2, !noundef ![[NOUNDEF]]{{$}}
9797
*x
9898
}
9999

@@ -107,7 +107,7 @@ pub fn load_nonzero_int(x: &NonZeroU16) -> NonZeroU16 {
107107
// CHECK-LABEL: @load_option_nonzero_int
108108
#[no_mangle]
109109
pub fn load_option_nonzero_int(x: &Option<NonZeroU16>) -> Option<NonZeroU16> {
110-
// CHECK: load i16, {{i16\*|ptr}} %x, align 2, !noundef !2{{$}}
110+
// CHECK: load i16, {{i16\*|ptr}} %x, align 2, !noundef ![[NOUNDEF]]{{$}}
111111
*x
112112
}
113113

tests/codegen/naked-functions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -C no-prepopulate-passes
1+
// compile-flags: -C no-prepopulate-passes -Copt-level=0
22
// needs-asm-support
33
// only-x86_64
44

@@ -19,7 +19,7 @@ pub unsafe extern "C" fn naked_empty() {
1919
}
2020

2121
// CHECK: Function Attrs: naked
22-
// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 noundef %a, i64 noundef %b)
22+
// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 %a, i64 %b)
2323
#[no_mangle]
2424
#[naked]
2525
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize {

tests/codegen/pic-relocation-model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// compile-flags: -C relocation-model=pic
1+
// compile-flags: -C relocation-model=pic -Copt-level=0
22

33
#![crate_type = "rlib"]
44

5-
// CHECK: define noundef i8 @call_foreign_fn()
5+
// CHECK: define i8 @call_foreign_fn()
66
#[no_mangle]
77
pub fn call_foreign_fn() -> u8 {
88
unsafe {
@@ -13,7 +13,7 @@ pub fn call_foreign_fn() -> u8 {
1313
// (Allow but do not require `zeroext` here, because it is not worth effort to
1414
// spell out which targets have it and which ones do not; see rust#97800.)
1515

16-
// CHECK: declare noundef{{( zeroext)?}} i8 @foreign_fn()
16+
// CHECK: declare{{( zeroext)?}} i8 @foreign_fn()
1717
extern "C" {fn foreign_fn() -> u8;}
1818

1919
// CHECK: !{i32 {{[78]}}, !"PIC Level", i32 2}

tests/codegen/pie-relocation-model.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// compile-flags: -C relocation-model=pie
1+
// compile-flags: -C relocation-model=pie -Copt-level=0
22
// only-x86_64-unknown-linux-gnu
33

44
#![crate_type = "rlib"]
55

66
// With PIE we know local functions cannot be interpositioned, we can mark them
77
// as dso_local.
8-
// CHECK: define dso_local noundef i8 @call_foreign_fn()
8+
// CHECK: define dso_local i8 @call_foreign_fn()
99
#[no_mangle]
1010
pub fn call_foreign_fn() -> u8 {
1111
unsafe {
@@ -15,7 +15,7 @@ pub fn call_foreign_fn() -> u8 {
1515

1616
// External functions are still marked as non-dso_local, since we don't know if the symbol
1717
// is defined in the binary or in the shared library.
18-
// CHECK: declare noundef zeroext i8 @foreign_fn()
18+
// CHECK: declare zeroext i8 @foreign_fn()
1919
extern "C" {fn foreign_fn() -> u8;}
2020

2121
// CHECK: !{i32 {{[78]}}, !"PIC Level", i32 2}

tests/codegen/refs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
1+
// compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0 -Copt-level=0
22

33
#![crate_type = "lib"]
44

55
// Hack to get the correct size for the length part in slices
6-
// CHECK: @helper([[USIZE:i[0-9]+]] noundef %_1)
6+
// CHECK: @helper([[USIZE:i[0-9]+]] %_1)
77
#[no_mangle]
88
pub fn helper(_: usize) {
99
}

tests/codegen/sanitizer-cfi-emit-type-checks.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Verifies that pointer type membership tests for indirect calls are emitted.
22
//
33
// needs-sanitizer-cfi
4-
// compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi
4+
// compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -Copt-level=0
55

66
#![crate_type="lib"]
77

@@ -11,7 +11,7 @@ pub fn foo(f: fn(i32) -> i32, arg: i32) -> i32 {
1111
// CHECK: [[TT:%.+]] = call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"{{[[:print:]]+}}")
1212
// CHECK-NEXT: br i1 [[TT]], label %type_test.pass, label %type_test.fail
1313
// CHECK: type_test.pass:
14-
// CHECK-NEXT: {{%.+}} = call noundef i32 %f(i32 noundef %arg)
14+
// CHECK-NEXT: {{%.+}} = call i32 %f(i32 %arg)
1515
// CHECK-NEXT: br label %bb1
1616
// CHECK: type_test.fail:
1717
// CHECK-NEXT: call void @llvm.trap()

0 commit comments

Comments
 (0)