Skip to content

Commit 13b9747

Browse files
committed
Update tests
1 parent a5cd911 commit 13b9747

5 files changed

Lines changed: 44 additions & 4 deletions

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,11 @@ llvm::APSInt GetIntegerLiteralValue(const clang::ASTContext &ctx,
324324
if (target->isBuiltinType() && target->isIntegerType() &&
325325
!target->isBooleanType()) {
326326
value = value.zextOrTrunc(ctx.getIntWidth(target));
327-
is_signed = target->isSpecificBuiltinType(clang::BuiltinType::Char_S) ||
328-
target->isSpecificBuiltinType(clang::BuiltinType::Char_U)
329-
? char_is_signed
330-
: target->isSignedIntegerType();
327+
is_signed =
328+
target->isSpecificBuiltinType(clang::BuiltinType::Char_S) ||
329+
target->isSpecificBuiltinType(clang::BuiltinType::Char_U)
330+
? char_is_signed
331+
: target->isSignedIntegerType();
331332
}
332333
return llvm::APSInt(value, !is_signed);
333334
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ impl RefCtor_unsigned_long_ {
3636
}
3737
}
3838
}
39+
pub fn neg_ll_1() -> i64 {
40+
return -9000000_i64;
41+
}
42+
pub fn neg_char_2() -> i8 {
43+
return (b'\x80' as i8);
44+
}
45+
pub fn neg_int_3() -> i32 {
46+
return -1;
47+
}
3948
pub fn main() {
4049
__cpp2rust_init_globals();
4150
std::process::exit(main_0());
@@ -54,6 +63,9 @@ fn main_0() -> i32 {
5463
let mut rc: RefCtor_unsigned_long_ =
5564
RefCtor_unsigned_long_::new({ (v1.as_pointer()).reinterpret_cast::<u64>() });
5665
assert!((rc.v == 7_u64));
66+
assert!((({ neg_ll_1() }) == (-9000000_i32 as i64)));
67+
assert!(((({ neg_char_2() }) as i32) == ((b'\x80' as i8) as i32)));
68+
assert!((({ neg_int_3() }) == -1_i32));
5769
return 0;
5870
}
5971
pub fn __cpp2rust_init_globals() {}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ fn main_0() -> i32 {
2828
let mut b: i32 = ({ sum_bytes_0((*g_packet_1.with(Value::clone).borrow()).clone(), 2_u32) });
2929
assert!((a == b));
3030
assert!((a == 1));
31+
let mut high: i32 = ({ sum_bytes_0(Ptr::<i8>::from_string_literal(b"\xc2\0A"), 3_u32) });
32+
assert!((high == (194 + 65)));
3133
let mut c: i32 = ((b"\r\n.\r\n"[(0) as usize] as i32) + (b"\r\n.\r\n"[(3) as usize] as i32));
3234
assert!((c == ((('\r' as i8) as i32) + (('\r' as i8) as i32))));
3335
let mut idx: i32 = 1;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ impl RefCtor_unsigned_long_ {
3636
this
3737
}
3838
}
39+
pub unsafe fn neg_ll_1() -> i64 {
40+
return -9000000_i64;
41+
}
42+
pub unsafe fn neg_char_2() -> libc::c_char {
43+
return (b'\x80' as libc::c_char);
44+
}
45+
pub unsafe fn neg_int_3() -> i32 {
46+
return -1;
47+
}
3948
pub fn main() {
4049
unsafe {
4150
__cpp2rust_init_globals();
@@ -55,6 +64,9 @@ unsafe fn main_0() -> i32 {
5564
let mut rc: RefCtor_unsigned_long_ =
5665
RefCtor_unsigned_long_::new({ &*(&raw const v1).cast::<u64>() });
5766
assert!(((rc.v) == (7_u64)));
67+
assert!(((unsafe { neg_ll_1() }) == (-9000000_i32 as i64)));
68+
assert!((((unsafe { neg_char_2() }) as i32) == ((b'\x80' as libc::c_char) as i32)));
69+
assert!(((unsafe { neg_int_3() }) == (-1_i32)));
5870
return 0;
5971
}
6072
pub unsafe fn __cpp2rust_init_globals() {}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ unsafe fn main_0() -> i32 {
5050
});
5151
assert!(((a) == (b)));
5252
assert!(((a) == (1)));
53+
let mut high: i32 = (unsafe {
54+
sum_bytes_0(
55+
(&[
56+
(-62 as libc::c_char),
57+
(0 as libc::c_char),
58+
(65 as libc::c_char),
59+
(0 as libc::c_char),
60+
])
61+
.as_ptr(),
62+
3_u32,
63+
)
64+
});
65+
assert!(((high) == ((194) + (65))));
5366
let mut c: i32 = (((*c"\r\n.\r\n".as_ptr().offset((0) as isize)) as i32)
5467
+ ((*c"\r\n.\r\n".as_ptr().offset((3) as isize)) as i32));
5568
assert!(((c) == ((('\r' as libc::c_char) as i32) + (('\r' as libc::c_char) as i32))));

0 commit comments

Comments
 (0)