about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@users.noreply.github.com>2024-07-30 11:06:26 +0200
committerAndreas Jonson <andjo403@users.noreply.github.com>2024-08-11 19:40:44 +0200
commitcfadfabfcd9644628422396fcc8a67244df435c1 (patch)
tree76631b2a21fc3d4b77d82a24278b6ea75693fd89 /tests/codegen
parent9bad7ba324099d124c77c5b06aebf68e11763f7b (diff)
downloadrust-cfadfabfcd9644628422396fcc8a67244df435c1.tar.gz
rust-cfadfabfcd9644628422396fcc8a67244df435c1.zip
Add range attribute to scalar function results and arguments
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/call-metadata.rs1
-rw-r--r--tests/codegen/cast-optimized.rs2
-rw-r--r--tests/codegen/common_prim_int_ptr.rs4
-rw-r--r--tests/codegen/enum/enum-match.rs2
-rw-r--r--tests/codegen/function-arguments.rs6
-rw-r--r--tests/codegen/issues/issue-68667-unwrap-combinators.rs2
-rw-r--r--tests/codegen/range-attribute.rs68
-rw-r--r--tests/codegen/repr/transparent.rs2
8 files changed, 77 insertions, 10 deletions
diff --git a/tests/codegen/call-metadata.rs b/tests/codegen/call-metadata.rs
index b2168990ff8..73c4b33e2cf 100644
--- a/tests/codegen/call-metadata.rs
+++ b/tests/codegen/call-metadata.rs
@@ -2,6 +2,7 @@
 // scalar value.
 
 //@ compile-flags: -O -C no-prepopulate-passes
+//@ ignore-llvm-version: 19 - 99
 
 #![crate_type = "lib"]
 
diff --git a/tests/codegen/cast-optimized.rs b/tests/codegen/cast-optimized.rs
index 313b2b4f0d6..59cf40935cd 100644
--- a/tests/codegen/cast-optimized.rs
+++ b/tests/codegen/cast-optimized.rs
@@ -20,8 +20,6 @@ pub fn u32_index(c: u32) -> [bool; 22] {
 // CHECK-LABEL: @char_as_u32_index
 #[no_mangle]
 pub fn char_as_u32_index(c: char) -> [bool; 22] {
-    // CHECK: %[[B:.+]] = icmp ult i32 %c, 1114112
-    // CHECK: call void @llvm.assume(i1 %[[B]])
     let c = c as u32;
 
     let mut array = [false; 22];
diff --git a/tests/codegen/common_prim_int_ptr.rs b/tests/codegen/common_prim_int_ptr.rs
index 87fa89abb86..aa7ebb4c911 100644
--- a/tests/codegen/common_prim_int_ptr.rs
+++ b/tests/codegen/common_prim_int_ptr.rs
@@ -28,7 +28,7 @@ pub fn insert_box(x: Box<()>) -> Result<usize, Box<()>> {
 
 // CHECK-LABEL: @extract_int
 // CHECK-NOT: nonnull
-// CHECK-SAME: (i{{[0-9]+}} {{[^,]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]])
+// CHECK-SAME: (i{{[0-9]+}} {{[^%]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]])
 #[no_mangle]
 pub unsafe fn extract_int(x: Result<usize, Box<()>>) -> usize {
     // CHECK: [[TEMP:%.+]] = ptrtoint ptr [[PAYLOAD]] to [[USIZE:i[0-9]+]]
@@ -40,7 +40,7 @@ pub unsafe fn extract_int(x: Result<usize, Box<()>>) -> usize {
 }
 
 // CHECK-LABEL: @extract_box
-// CHECK-SAME: (i{{[0-9]+}} {{[^,]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]])
+// CHECK-SAME: (i{{[0-9]+}} {{[^%]+}} [[DISCRIMINANT:%[0-9]+]], ptr {{[^,]+}} [[PAYLOAD:%[0-9]+]])
 #[no_mangle]
 pub unsafe fn extract_box(x: Result<usize, Box<i32>>) -> Box<i32> {
     // CHECK: ret ptr [[PAYLOAD]]
diff --git a/tests/codegen/enum/enum-match.rs b/tests/codegen/enum/enum-match.rs
index 8da5de63e67..a24b98050d2 100644
--- a/tests/codegen/enum/enum-match.rs
+++ b/tests/codegen/enum/enum-match.rs
@@ -34,7 +34,7 @@ pub enum Enum1 {
 
 // CHECK: define noundef{{( range\(i8 [0-9]+, [0-9]+\))?}} i8 @match1{{.*}}
 // CHECK-NEXT: start:
-// CHECK-NEXT: %1 = add i8 %0, -2
+// CHECK-NEXT: %1 = add{{( nsw)?}} i8 %0, -2
 // CHECK-NEXT: %2 = zext i8 %1 to i64
 // CHECK-NEXT: %3 = icmp ult i8 %1, 2
 // CHECK-NEXT: %4 = add nuw nsw i64 %2, 1
diff --git a/tests/codegen/function-arguments.rs b/tests/codegen/function-arguments.rs
index 56504df4034..bf9f405192b 100644
--- a/tests/codegen/function-arguments.rs
+++ b/tests/codegen/function-arguments.rs
@@ -50,7 +50,7 @@ pub fn maybeuninit_enum_bool(x: MaybeUninit<MyBool>) -> MaybeUninit<MyBool> {
     x
 }
 
-// CHECK: noundef i32 @char(i32 noundef %x)
+// CHECK: noundef{{( range\(i32 0, 1114112\))?}} i32 @char(i32 noundef{{( range\(i32 0, 1114112\))?}} %x)
 #[no_mangle]
 pub fn char(x: char) -> char {
     x
@@ -68,7 +68,7 @@ pub fn int(x: u64) -> u64 {
     x
 }
 
-// CHECK: noundef i64 @nonzero_int(i64 noundef %x)
+// CHECK: noundef{{( range\(i64 1, 0\))?}} i64 @nonzero_int(i64 noundef{{( range\(i64 1, 0\))?}} %x)
 #[no_mangle]
 pub fn nonzero_int(x: NonZero<u64>) -> NonZero<u64> {
     x
@@ -250,7 +250,7 @@ pub fn return_slice(x: &[u16]) -> &[u16] {
     x
 }
 
-// CHECK: { i16, i16 } @enum_id_1(i16 noundef %x.0, i16 %x.1)
+// CHECK: { i16, i16 } @enum_id_1(i16 noundef{{( range\(i16 0, 3\))?}} %x.0, i16 %x.1)
 #[no_mangle]
 pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
     x
diff --git a/tests/codegen/issues/issue-68667-unwrap-combinators.rs b/tests/codegen/issues/issue-68667-unwrap-combinators.rs
index 6bd4c566a0c..21a5a5bf4ee 100644
--- a/tests/codegen/issues/issue-68667-unwrap-combinators.rs
+++ b/tests/codegen/issues/issue-68667-unwrap-combinators.rs
@@ -5,7 +5,7 @@
 // MIR inlining now optimizes this code.
 
 // CHECK-LABEL: @unwrap_combinators
-// CHECK: icmp
+// CHECK: {{icmp|trunc}}
 // CHECK-NEXT: icmp
 // CHECK-NEXT: select i1
 // CHECK-NEXT: ret i1
diff --git a/tests/codegen/range-attribute.rs b/tests/codegen/range-attribute.rs
new file mode 100644
index 00000000000..bb19bec0fb9
--- /dev/null
+++ b/tests/codegen/range-attribute.rs
@@ -0,0 +1,68 @@
+// Checks that range metadata gets emitted on functions result and arguments
+// with scalar value.
+
+//@ compile-flags: -O -C no-prepopulate-passes
+//@ min-llvm-version: 19
+
+#![crate_type = "lib"]
+
+use std::num::NonZero;
+
+// Hack to get the correct size for usize
+// CHECK: @helper([[USIZE:i[0-9]+]] noundef %_1)
+#[no_mangle]
+pub fn helper(_: usize) {}
+
+// CHECK: noundef range(i128 1, 0) i128 @nonzero_int(i128 noundef range(i128 1, 0) %x)
+#[no_mangle]
+pub fn nonzero_int(x: NonZero<u128>) -> NonZero<u128> {
+    x
+}
+
+// CHECK: noundef range(i8 0, 3) i8 @optional_bool(i8 noundef range(i8 0, 3) %x)
+#[no_mangle]
+pub fn optional_bool(x: Option<bool>) -> Option<bool> {
+    x
+}
+
+pub enum Enum0 {
+    A(bool),
+    B,
+    C,
+}
+
+// CHECK: noundef range(i8 0, 4) i8 @enum0_value(i8 noundef range(i8 0, 4) %x)
+#[no_mangle]
+pub fn enum0_value(x: Enum0) -> Enum0 {
+    x
+}
+
+pub enum Enum1 {
+    A(u64),
+    B(u64),
+    C(u64),
+}
+
+// CHECK: { [[ENUM1_TYP:i[0-9]+]], i64 } @enum1_value([[ENUM1_TYP]] noundef range([[ENUM1_TYP]] 0, 3) %x.0, i64 noundef %x.1)
+#[no_mangle]
+pub fn enum1_value(x: Enum1) -> Enum1 {
+    x
+}
+
+pub enum Enum2 {
+    A(Enum0),
+    B(Enum0),
+    C(Enum0),
+}
+
+// CHECK: { i8, i8 } @enum2_value(i8 noundef range(i8 0, 3) %x.0, i8 noundef %x.1)
+#[no_mangle]
+pub fn enum2_value(x: Enum2) -> Enum2 {
+    x
+}
+
+// CHECK: noundef [[USIZE]] @takes_slice(ptr noalias noundef nonnull readonly align 4 %x.0, [[USIZE]] noundef %x.1)
+#[no_mangle]
+pub fn takes_slice(x: &[i32]) -> usize {
+    x.len()
+}
diff --git a/tests/codegen/repr/transparent.rs b/tests/codegen/repr/transparent.rs
index 4b41332db45..9140b8542ec 100644
--- a/tests/codegen/repr/transparent.rs
+++ b/tests/codegen/repr/transparent.rs
@@ -74,7 +74,7 @@ pub enum Bool {
     FileNotFound,
 }
 
-// CHECK: define{{( dso_local)?}} noundef{{( zeroext)?}} i8 @test_Gpz(i8 noundef{{( zeroext)?}} %_1)
+// CHECK: define{{( dso_local)?}} noundef{{( zeroext)?( range\(i8 0, 3\))?}} i8 @test_Gpz(i8 noundef{{( zeroext)?( range\(i8 0, 3\))?}} %_1)
 #[no_mangle]
 pub extern "C" fn test_Gpz(_: GenericPlusZst<Bool>) -> GenericPlusZst<Bool> {
     loop {}