Skip to content

Commit 71ff272

Browse files
committed
Add rules for __builtin_abort/nanf/inff/clzl
1 parent bbcef07 commit 71ff272

5 files changed

Lines changed: 90 additions & 8 deletions

File tree

‎rules/builtin/src.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ void f11(void) { return __builtin_ia32_pause(); }
3232
void *f14(void *dst, const void *src, size_t n) {
3333
return __builtin_memcpy(dst, src, n);
3434
}
35+
36+
void f15() { return __builtin_abort(); }
37+
38+
int f16(unsigned long x) { return __builtin_clzl(x); }
39+
40+
float f17() { return __builtin_inff(); }
41+
42+
float f18(const char *tagp) { return __builtin_nanf(tagp); }

‎rules/builtin/tgt_unsafe.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,17 @@ unsafe fn f14(a0: *mut u8, a1: *const u8, a2: usize) -> *mut u8 {
5757
}
5858
a0
5959
}
60+
61+
unsafe fn f15() { std::process::abort() }
62+
63+
unsafe fn f16(a0: u64) -> i32 {
64+
a0.leading_zeros() as i32
65+
}
66+
67+
unsafe fn f17() -> f32 {
68+
f32::INFINITY
69+
}
70+
71+
unsafe fn f18(a0: *const ::core::ffi::c_char) -> f32 {
72+
f32::NAN
73+
}

‎tests/unit/builtin.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ static void test_popcountl(void) {
5353
assert(__builtin_popcountl(0xFFUL) == 8);
5454
}
5555

56+
static void test_clzl(void) {
57+
assert(__builtin_clzl(1UL) == 63);
58+
assert(__builtin_clzl(0x8000000000000000UL) == 0);
59+
}
60+
61+
static void test_inff(void) {
62+
float inf = __builtin_inff();
63+
assert(inf > 0.0f);
64+
assert(inf == inf * 2.0f);
65+
assert(1.0f / inf == 0.0f);
66+
}
67+
68+
static void test_nanf(void) {
69+
float nan = __builtin_nanf("");
70+
assert(nan != nan);
71+
assert(!(nan < 0.0f));
72+
assert(!(nan > 0.0f));
73+
}
74+
5675
static void test_mul_overflow_long(void) {
5776
long r = 0;
5877
assert(!__builtin_mul_overflow(3L, 7L, &r));
@@ -76,6 +95,9 @@ int main(void) {
7695
test_bswap64();
7796
test_ctzl();
7897
test_popcountl();
98+
test_clzl();
99+
test_inff();
100+
test_nanf();
79101
test_mul_overflow_long();
80102
test_mul_overflow_long_long();
81103
return 0;

‎tests/unit/out/refcount/builtin.rs‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,23 @@ pub fn test_popcountl_7() {
3535
assert!((((0_u64.count_ones() as i32 == 0) as i32) != 0));
3636
assert!((((255_u64.count_ones() as i32 == 8) as i32) != 0));
3737
}
38-
pub fn test_mul_overflow_long_8() {
38+
pub fn test_clzl_8() {
39+
assert!((((1_u64.leading_zeros() as i32 == 63) as i32) != 0));
40+
assert!((((9223372036854775808_u64.leading_zeros() as i32 == 0) as i32) != 0));
41+
}
42+
pub fn test_inff_9() {
43+
let inf: Value<f32> = Rc::new(RefCell::new(f32::INFINITY));
44+
assert!(((((*inf.borrow()) > 0.0E+0) as i32) != 0));
45+
assert!(((((*inf.borrow()) == ((*inf.borrow()) * 2.0E+0)) as i32) != 0));
46+
assert!(((((1.0E+0 / (*inf.borrow())) == 0.0E+0) as i32) != 0));
47+
}
48+
pub fn test_nanf_10() {
49+
let nan: Value<f32> = Rc::new(RefCell::new(f32::NAN));
50+
assert!(((((*nan.borrow()) != (*nan.borrow())) as i32) != 0));
51+
assert!(((!((((*nan.borrow()) < 0.0E+0) as i32) != 0) as i32) != 0));
52+
assert!(((!((((*nan.borrow()) > 0.0E+0) as i32) != 0) as i32) != 0));
53+
}
54+
pub fn test_mul_overflow_long_11() {
3955
let r: Value<i64> = Rc::new(RefCell::new(0_i64));
4056
assert!(
4157
((!({
@@ -52,7 +68,7 @@ pub fn test_mul_overflow_long_8() {
5268
ovf
5369
});
5470
}
55-
pub fn test_mul_overflow_long_long_9() {
71+
pub fn test_mul_overflow_long_long_12() {
5672
let r: Value<i64> = Rc::new(RefCell::new(0_i64));
5773
assert!(
5874
((!({
@@ -82,8 +98,11 @@ fn main_0() -> i32 {
8298
({ test_bswap64_5() });
8399
({ test_ctzl_6() });
84100
({ test_popcountl_7() });
85-
({ test_mul_overflow_long_8() });
86-
({ test_mul_overflow_long_long_9() });
101+
({ test_clzl_8() });
102+
({ test_inff_9() });
103+
({ test_nanf_10() });
104+
({ test_mul_overflow_long_11() });
105+
({ test_mul_overflow_long_long_12() });
87106
return 0;
88107
}
89108
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/builtin.rs‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,23 @@ pub unsafe fn test_popcountl_7() {
3535
assert!(((((0_u64.count_ones() as i32) == (0)) as i32) != 0));
3636
assert!(((((255_u64.count_ones() as i32) == (8)) as i32) != 0));
3737
}
38-
pub unsafe fn test_mul_overflow_long_8() {
38+
pub unsafe fn test_clzl_8() {
39+
assert!(((((1_u64.leading_zeros() as i32) == (63)) as i32) != 0));
40+
assert!(((((9223372036854775808_u64.leading_zeros() as i32) == (0)) as i32) != 0));
41+
}
42+
pub unsafe fn test_inff_9() {
43+
let mut inf: f32 = f32::INFINITY;
44+
assert!(((((inf) > (0.0E+0)) as i32) != 0));
45+
assert!(((((inf) == ((inf) * (2.0E+0))) as i32) != 0));
46+
assert!((((((1.0E+0) / (inf)) == (0.0E+0)) as i32) != 0));
47+
}
48+
pub unsafe fn test_nanf_10() {
49+
let mut nan: f32 = f32::NAN;
50+
assert!(((((nan) != (nan)) as i32) != 0));
51+
assert!(((!((((nan) < (0.0E+0)) as i32) != 0) as i32) != 0));
52+
assert!(((!((((nan) > (0.0E+0)) as i32) != 0) as i32) != 0));
53+
}
54+
pub unsafe fn test_mul_overflow_long_11() {
3955
let mut r: i64 = 0_i64;
4056
assert!(
4157
((!({
@@ -52,7 +68,7 @@ pub unsafe fn test_mul_overflow_long_8() {
5268
ovf
5369
});
5470
}
55-
pub unsafe fn test_mul_overflow_long_long_9() {
71+
pub unsafe fn test_mul_overflow_long_long_12() {
5672
let mut r: i64 = 0_i64;
5773
assert!(
5874
((!({
@@ -84,8 +100,11 @@ unsafe fn main_0() -> i32 {
84100
(unsafe { test_bswap64_5() });
85101
(unsafe { test_ctzl_6() });
86102
(unsafe { test_popcountl_7() });
87-
(unsafe { test_mul_overflow_long_8() });
88-
(unsafe { test_mul_overflow_long_long_9() });
103+
(unsafe { test_clzl_8() });
104+
(unsafe { test_inff_9() });
105+
(unsafe { test_nanf_10() });
106+
(unsafe { test_mul_overflow_long_11() });
107+
(unsafe { test_mul_overflow_long_long_12() });
89108
return 0;
90109
}
91110
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)