Skip to content

Commit 0919931

Browse files
committed
Add LLVM codegen tests for new Arc implementation
1 parent 84393bc commit 0919931

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

tests/codegen-llvm/lib-optimizations/rc-arc-optimizations.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![crate_type = "lib"]
44

55
use std::rc::{self, Rc};
6+
use std::sync::{self, Arc};
67

78
// Ensures that we can create array of `Weak`s using `memset`.
89

@@ -15,7 +16,17 @@ pub fn array_of_rc_weak() -> [rc::Weak<u32>; 100] {
1516
[(); 100].map(|()| rc::Weak::new())
1617
}
1718

18-
// Ensures that we convert `&Option<Rc<T>>` to `Option<&T>` without checking for `None`.
19+
#[no_mangle]
20+
pub fn array_of_sync_weak() -> [sync::Weak<u32>; 100] {
21+
// CHECK-LABEL: @array_of_sync_weak(
22+
// CHECK-NEXT: start:
23+
// CHECK-NEXT: call void @llvm.memset.
24+
// CHECK-NEXT: ret void
25+
[(); 100].map(|()| sync::Weak::new())
26+
}
27+
28+
// Ensures that we convert `&Option<Rc<T>>` and `&Option<Arc<T>>` to `Option<&T>` without checking
29+
// for `None`.
1930

2031
#[no_mangle]
2132
pub fn option_rc_as_deref_no_cmp(rc: &Option<Rc<u32>>) -> Option<&u32> {
@@ -25,3 +36,12 @@ pub fn option_rc_as_deref_no_cmp(rc: &Option<Rc<u32>>) -> Option<&u32> {
2536
// CHECK-NEXT: ret ptr %[[RC]]
2637
rc.as_deref()
2738
}
39+
40+
#[no_mangle]
41+
pub fn option_arc_as_deref_no_cmp(arc: &Option<Arc<u32>>) -> Option<&u32> {
42+
// CHECK-LABEL: @option_arc_as_deref_no_cmp(ptr
43+
// CHECK-NEXT: start:
44+
// CHECK-NEXT: %[[ARC:.+]] = load ptr, ptr %arc
45+
// CHECK-NEXT: ret ptr %[[ARC]]
46+
arc.as_deref()
47+
}

0 commit comments

Comments
 (0)