From ab958aeaade3510b80fe9a17237a0cc42ae12bf9 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 5 Nov 2026 14:36:25 +0000 Subject: [PATCH 1/3] Translate std::abs on long and long long as i64 --- rules/cmath/tgt_unsafe.rs | 4 ++-- tests/unit/cmath_abs_long.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/unit/cmath_abs_long.cpp diff --git a/rules/cmath/tgt_unsafe.rs b/rules/cmath/tgt_unsafe.rs index 22beec944d..c794c52c45 100644 --- a/rules/cmath/tgt_unsafe.rs +++ b/rules/cmath/tgt_unsafe.rs @@ -4,10 +4,10 @@ unsafe fn f1(a0: i32) -> i32 { a0.abs() } -unsafe fn f2(a0: i32) -> i32 { +unsafe fn f2(a0: i64) -> i64 { a0.abs() } -unsafe fn f3(a0: i32) -> i32 { +unsafe fn f3(a0: i64) -> i64 { a0.abs() } unsafe fn f4(a0: f64) -> f64 { diff --git a/tests/unit/cmath_abs_long.cpp b/tests/unit/cmath_abs_long.cpp new file mode 100644 index 0000000000..8cb29a59e4 --- /dev/null +++ b/tests/unit/cmath_abs_long.cpp @@ -0,0 +1,16 @@ +#include +#include + +int main() { + long l = -5000000000L; + long long ll = -6000000000LL; + assert(std::abs(l) == 5000000000L); + assert(std::abs(ll) == 6000000000LL); + long small = -7; + long long small_ll = -8; + int narrowed = std::abs(small); + int narrowed_ll = std::abs(small_ll); + assert(narrowed == 7); + assert(narrowed_ll == 8); + return 0; +} From 72ab6ebca02f6f3c6abd5a8a0294bdcbe4b8de78 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 5 Nov 2026 14:46:52 +0000 Subject: [PATCH 2/3] Extend existing tests --- tests/unit/cmath_abs_long.cpp | 16 ---------------- tests/unit/fft.cpp | 10 ++++++++++ 2 files changed, 10 insertions(+), 16 deletions(-) delete mode 100644 tests/unit/cmath_abs_long.cpp diff --git a/tests/unit/cmath_abs_long.cpp b/tests/unit/cmath_abs_long.cpp deleted file mode 100644 index 8cb29a59e4..0000000000 --- a/tests/unit/cmath_abs_long.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include - -int main() { - long l = -5000000000L; - long long ll = -6000000000LL; - assert(std::abs(l) == 5000000000L); - assert(std::abs(ll) == 6000000000LL); - long small = -7; - long long small_ll = -8; - int narrowed = std::abs(small); - int narrowed_ll = std::abs(small_ll); - assert(narrowed == 7); - assert(narrowed_ll == 8); - return 0; -} diff --git a/tests/unit/fft.cpp b/tests/unit/fft.cpp index a2e0018fb4..bfc5de0def 100644 --- a/tests/unit/fft.cpp +++ b/tests/unit/fft.cpp @@ -67,5 +67,15 @@ int main() { } assert(reals[0] == 10 && imgs[0] == 0 && reals[1] == -2 && imgs[1] == 2 && reals[2] == -2 && imgs[2] == 0 && reals[3] == -2 && imgs[3] == -2); + long l = -5000000000L; + long long ll = -6000000000LL; + assert(std::abs(l) == 5000000000L); + assert(std::abs(ll) == 6000000000LL); + long small = -7; + long long small_ll = -8; + int narrowed = std::abs(small); + int narrowed_ll = std::abs(small_ll); + assert(narrowed == 7); + assert(narrowed_ll == 8); return 0; } From 3708d99ccd6c1eb1721257118df0e5b1f0d0aefc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 5 Nov 2026 15:02:46 +0000 Subject: [PATCH 3/3] Update tests --- tests/unit/out/refcount/fft.rs | 10 ++++++++++ tests/unit/out/unsafe/fft.rs | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index c9cfc623df..3aa6ff7f1f 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -259,6 +259,16 @@ fn main_0() -> i32 { .read()) == -2_i32) ); + let mut l: i64 = -5000000000_i64; + let mut ll: i64 = -6000000000_i64; + assert!((l.abs() == 5000000000_i64)); + assert!((ll.abs() == 6000000000_i64)); + let mut small: i64 = (-7_i32 as i64); + let mut small_ll: i64 = (-8_i32 as i64); + let mut narrowed: i32 = (small.abs() as i32); + let mut narrowed_ll: i32 = (small_ll.abs() as i32); + assert!((narrowed == 7)); + assert!((narrowed_ll == 8)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/fft.rs b/tests/unit/out/unsafe/fft.rs index ed6152ab29..a5c4853645 100644 --- a/tests/unit/out/unsafe/fft.rs +++ b/tests/unit/out/unsafe/fft.rs @@ -266,6 +266,16 @@ unsafe fn main_0() -> i32 { .add(3_usize)) == (-2_i32)) ); + let mut l: i64 = -5000000000_i64; + let mut ll: i64 = -6000000000_i64; + assert!(((l.abs()) == (5000000000_i64))); + assert!(((ll.abs()) == (6000000000_i64))); + let mut small: i64 = (-7_i32 as i64); + let mut small_ll: i64 = (-8_i32 as i64); + let mut narrowed: i32 = (small.abs() as i32); + let mut narrowed_ll: i32 = (small_ll.abs() as i32); + assert!(((narrowed) == (7))); + assert!(((narrowed_ll) == (8))); return 0; } pub unsafe fn __cpp2rust_init_globals() {}