about summary refs log tree commit diff
path: root/tests/codegen/checked_math.rs
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2024-06-22 23:00:44 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2024-06-23 13:29:06 -0700
commitec9e35618dd9d4b55282b340aa29fb8c78691aca (patch)
treeac6dfb130ec55f448cd16a68a129bfc0fa78079c /tests/codegen/checked_math.rs
parentacb62737aca7045f331e7a05adc38bed213e278d (diff)
downloadrust-ec9e35618dd9d4b55282b340aa29fb8c78691aca.tar.gz
rust-ec9e35618dd9d4b55282b340aa29fb8c78691aca.zip
Also get `add nuw` from `uN::checked_add`
Diffstat (limited to 'tests/codegen/checked_math.rs')
-rw-r--r--tests/codegen/checked_math.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/codegen/checked_math.rs b/tests/codegen/checked_math.rs
index 41016e3b7be..75df5866d6e 100644
--- a/tests/codegen/checked_math.rs
+++ b/tests/codegen/checked_math.rs
@@ -84,3 +84,17 @@ pub fn checked_shr_signed(a: i32, b: u32) -> Option<i32> {
     // CHECK: ret { i32, i32 } %[[R1]]
     a.checked_shr(b)
 }
+
+// CHECK-LABEL: @checked_add_one_unwrap_unsigned
+// CHECK-SAME: (i32 noundef %x)
+#[no_mangle]
+pub fn checked_add_one_unwrap_unsigned(x: u32) -> u32 {
+    // CHECK: %[[IS_MAX:.+]] = icmp eq i32 %x, -1
+    // CHECK: br i1 %[[IS_MAX]], label %[[NONE_BB:.+]], label %[[SOME_BB:.+]]
+    // CHECK: [[SOME_BB]]:
+    // CHECK: %[[R:.+]] = add nuw i32 %x, 1
+    // CHECK: ret i32 %[[R]]
+    // CHECK: [[NONE_BB]]:
+    // CHECK: call {{.+}}unwrap_failed
+    x.checked_add(1).unwrap()
+}