From 9160b7900fdc18ad115290b4c46dc00ede03453d Mon Sep 17 00:00:00 2001 From: Jamie Hill-Daniel Date: Thu, 14 Aug 2025 13:32:31 +0000 Subject: [PATCH] Add codegen test for issue 138497 --- ...sue-138497-nonzero-remove-trailing-zeroes.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/codegen-llvm/issues/issue-138497-nonzero-remove-trailing-zeroes.rs diff --git a/tests/codegen-llvm/issues/issue-138497-nonzero-remove-trailing-zeroes.rs b/tests/codegen-llvm/issues/issue-138497-nonzero-remove-trailing-zeroes.rs new file mode 100644 index 0000000000000..33e89a0716d66 --- /dev/null +++ b/tests/codegen-llvm/issues/issue-138497-nonzero-remove-trailing-zeroes.rs @@ -0,0 +1,17 @@ +//! This test checks that removing trailing zeroes from a `NonZero`, +//! then creating a new `NonZero` from the result does not panic. + +//@ min-llvm-version: 21 +//@ compile-flags: -O -Zmerge-functions=disabled +#![crate_type = "lib"] + +use std::num::NonZero; + +// CHECK-LABEL: @remove_trailing_zeros +#[no_mangle] +pub fn remove_trailing_zeros(x: NonZero) -> NonZero { + // CHECK-NOT: unwrap_failed + // CHECK-NOT: br + // CHECK ret i8 + NonZero::new(x.get() >> x.trailing_zeros()).unwrap() +}