mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-12 23:13:15 +00:00
Make Rc<T>::deref
and Arc<T>::deref
zero-cost
This commit is contained in:
parent
c705b7d6f7
commit
5f9be420f4
@ -213,6 +213,8 @@ mod testing;
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
#[cfg(not(no_rc))]
|
||||
mod raw_rc;
|
||||
mod raw_vec;
|
||||
|
||||
// Heaps provided for low-level allocation strategies
|
||||
|
2388
library/alloc/src/raw_rc.rs
Normal file
2388
library/alloc/src/raw_rc.rs
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -61,16 +61,20 @@ fn weak_self_cyclic() {
|
||||
|
||||
#[test]
|
||||
fn is_unique() {
|
||||
fn rc_is_unique(rc: &Rc<i32>) -> bool {
|
||||
unsafe { <RcOps as crate::raw_rc::RcOps>::is_unique(rc.raw_rc.ref_counts()) }
|
||||
}
|
||||
|
||||
let x = Rc::new(3);
|
||||
assert!(Rc::is_unique(&x));
|
||||
assert!(rc_is_unique(&x));
|
||||
let y = x.clone();
|
||||
assert!(!Rc::is_unique(&x));
|
||||
assert!(!rc_is_unique(&x));
|
||||
drop(y);
|
||||
assert!(Rc::is_unique(&x));
|
||||
assert!(rc_is_unique(&x));
|
||||
let w = Rc::downgrade(&x);
|
||||
assert!(!Rc::is_unique(&x));
|
||||
assert!(!rc_is_unique(&x));
|
||||
drop(w);
|
||||
assert!(Rc::is_unique(&x));
|
||||
assert!(rc_is_unique(&x));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -182,14 +182,29 @@ class StdVecDequeProvider(printer_base):
|
||||
return "array"
|
||||
|
||||
|
||||
_REF_COUNTS_PTR_TYPE = None
|
||||
|
||||
|
||||
def _get_ref_counts_ptr_type():
|
||||
global _REF_COUNTS_PTR_TYPE
|
||||
|
||||
if _REF_COUNTS_PTR_TYPE is None:
|
||||
_REF_COUNTS_PTR_TYPE = gdb.lookup_type("alloc::raw_rc::RefCounts").pointer()
|
||||
|
||||
return _REF_COUNTS_PTR_TYPE
|
||||
|
||||
|
||||
class StdRcProvider(printer_base):
|
||||
def __init__(self, valobj, is_atomic=False):
|
||||
self._valobj = valobj
|
||||
self._is_atomic = is_atomic
|
||||
self._ptr = unwrap_unique_or_non_null(valobj["ptr"])
|
||||
self._value = self._ptr["data" if is_atomic else "value"]
|
||||
self._strong = self._ptr["strong"]["v" if is_atomic else "value"]["value"]
|
||||
self._weak = self._ptr["weak"]["v" if is_atomic else "value"]["value"] - 1
|
||||
self._ptr = unwrap_unique_or_non_null(valobj["raw_rc"]["weak"]["ptr"])
|
||||
self._value = self._ptr.dereference()
|
||||
|
||||
ref_counts_ptr = self._ptr.reinterpret_cast(_get_ref_counts_ptr_type()) - 1
|
||||
|
||||
self._strong = ref_counts_ptr["strong"]["value"]
|
||||
self._weak = ref_counts_ptr["weak"]["value"] - 1
|
||||
|
||||
def to_string(self):
|
||||
if self._is_atomic:
|
||||
|
@ -1,6 +1,7 @@
|
||||
import sys
|
||||
|
||||
from lldb import (
|
||||
SBAddress,
|
||||
SBData,
|
||||
SBError,
|
||||
SBValue,
|
||||
@ -675,6 +676,18 @@ def StdRcSummaryProvider(valobj: SBValue, _dict: LLDBOpaque) -> str:
|
||||
return "strong={}, weak={}".format(strong, weak)
|
||||
|
||||
|
||||
_REF_COUNTS_TYPE = None
|
||||
|
||||
|
||||
def _get_or_init_ref_counts_type(target):
|
||||
global _REF_COUNTS_TYPE
|
||||
|
||||
if _REF_COUNTS_TYPE is None:
|
||||
_REF_COUNTS_TYPE = target.FindFirstType("alloc::raw_rc::RefCounts")
|
||||
|
||||
return _REF_COUNTS_TYPE
|
||||
|
||||
|
||||
class StdRcSyntheticProvider:
|
||||
"""Pretty-printer for alloc::rc::Rc<T> and alloc::sync::Arc<T>
|
||||
|
||||
@ -694,21 +707,33 @@ class StdRcSyntheticProvider:
|
||||
def __init__(self, valobj: SBValue, _dict: LLDBOpaque, is_atomic: bool = False):
|
||||
self.valobj = valobj
|
||||
|
||||
self.ptr = unwrap_unique_or_non_null(self.valobj.GetChildMemberWithName("ptr"))
|
||||
|
||||
self.value = self.ptr.GetChildMemberWithName("data" if is_atomic else "value")
|
||||
|
||||
self.strong = (
|
||||
self.ptr.GetChildMemberWithName("strong")
|
||||
.GetChildAtIndex(0)
|
||||
.GetChildMemberWithName("value")
|
||||
ptr = (
|
||||
self.valobj.GetChildMemberWithName("raw_rc")
|
||||
.GetChildMemberWithName("weak")
|
||||
.GetChildMemberWithName("ptr")
|
||||
.GetChildMemberWithName("pointer")
|
||||
)
|
||||
self.weak = (
|
||||
self.ptr.GetChildMemberWithName("weak")
|
||||
.GetChildAtIndex(0)
|
||||
.GetChildMemberWithName("value")
|
||||
|
||||
self.value = ptr.deref.Clone("value")
|
||||
|
||||
target = valobj.GetTarget()
|
||||
ref_counts_type = _get_or_init_ref_counts_type(target)
|
||||
ref_counts_address = ptr.GetValueAsUnsigned() - ref_counts_type.size
|
||||
|
||||
ref_counts_value = target.CreateValueFromAddress(
|
||||
"ref_counts",
|
||||
SBAddress(ref_counts_address, target),
|
||||
ref_counts_type,
|
||||
)
|
||||
|
||||
self.strong = ref_counts_value.GetChildMemberWithName(
|
||||
"strong"
|
||||
).GetChildMemberWithName("value")
|
||||
|
||||
self.weak = ref_counts_value.GetChildMemberWithName(
|
||||
"weak"
|
||||
).GetChildMemberWithName("value")
|
||||
|
||||
self.value_builder = ValueBuilder(valobj)
|
||||
|
||||
self.update()
|
||||
|
@ -73,117 +73,116 @@
|
||||
-->
|
||||
<!-- alloc::rc::Rc<T> -->
|
||||
<Type Name="alloc::rc::Rc<*>">
|
||||
<DisplayString Optional="true">{ptr.pointer->value}</DisplayString>
|
||||
<DisplayString Optional="true">{*raw_rc.weak.ptr.pointer}</DisplayString>
|
||||
<Expand>
|
||||
<!-- thin -->
|
||||
<ExpandedItem Optional="true">ptr.pointer->value</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
|
||||
<ExpandedItem Optional="true">*raw_rc.weak.ptr.pointer</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer - 1)->weak</Item>
|
||||
|
||||
<!-- dyn -->
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.pointer - 1)->weak</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::rc::Rc<[T]> -->
|
||||
<Type Name="alloc::rc::Rc<slice2$<*>,*>">
|
||||
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
|
||||
<DisplayString>{{ len={raw_rc.weak.ptr.pointer.length} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
|
||||
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
|
||||
<Item Name="[Length]" ExcludeView="simple">raw_rc.weak.ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.data_ptr - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.data_ptr - 1)->weak</Item>
|
||||
<ArrayItems>
|
||||
<Size>ptr.pointer.length</Size>
|
||||
<!-- We add +2 to the data_ptr in order to skip the ref count fields in the RcInner -->
|
||||
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
|
||||
<Size>raw_rc.weak.ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)raw_rc.weak.ptr.pointer.data_ptr</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::rc::Weak<T> -->
|
||||
<Type Name="alloc::rc::Weak<*>">
|
||||
<DisplayString Optional="true">{ptr.pointer->value}</DisplayString>
|
||||
<DisplayString Optional="true">{*raw_weak.ptr.pointer}</DisplayString>
|
||||
<Expand>
|
||||
<!-- thin -->
|
||||
<ExpandedItem Optional="true">ptr.pointer->value</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
|
||||
<ExpandedItem Optional="true">*raw_weak.ptr.pointer</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer - 1)->weak</Item>
|
||||
|
||||
<!-- dyn -->
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.pointer - 1)->weak</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::rc::Weak<[T]> -->
|
||||
<Type Name="alloc::rc::Weak<slice2$<*>,*>">
|
||||
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
|
||||
<DisplayString>{{ len={raw_weak.ptr.pointer.length} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
|
||||
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
|
||||
<Item Name="[Length]" ExcludeView="simple">raw_weak.ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.data_ptr - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.data_ptr - 1)->weak</Item>
|
||||
<ArrayItems>
|
||||
<Size>ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
|
||||
<Size>raw_weak.ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)raw_weak.ptr.pointer.data_ptr</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::sync::Arc<T> -->
|
||||
<Type Name="alloc::sync::Arc<*>">
|
||||
<DisplayString Optional="true">{ptr.pointer->data}</DisplayString>
|
||||
<DisplayString Optional="true">{*raw_rc.weak.ptr.pointer}</DisplayString>
|
||||
<Expand>
|
||||
<!-- thin -->
|
||||
<ExpandedItem Optional="true">ptr.pointer->data</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
|
||||
<ExpandedItem Optional="true">*raw_rc.weak.ptr.pointer</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer - 1)->weak</Item>
|
||||
|
||||
<!-- dyn -->
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.pointer - 1)->weak</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::sync::Arc<[T]> -->
|
||||
<Type Name="alloc::sync::Arc<slice2$<*>,*>">
|
||||
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
|
||||
<DisplayString>{{ len={raw_rc.weak.ptr.pointer.length} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
|
||||
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
|
||||
<Item Name="[Length]" ExcludeView="simple">raw_rc.weak.ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.data_ptr - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]">((alloc::raw_rc::RefCounts *)raw_rc.weak.ptr.pointer.data_ptr - 1)->weak</Item>
|
||||
<ArrayItems>
|
||||
<Size>ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
|
||||
<Size>raw_rc.weak.ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)raw_rc.weak.ptr.pointer.data_ptr</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::sync::Weak<T> -->
|
||||
<Type Name="alloc::sync::Weak<*>">
|
||||
<DisplayString Optional="true">{ptr.pointer->data}</DisplayString>
|
||||
<DisplayString Optional="true">{*raw_weak.ptr.pointer}</DisplayString>
|
||||
<Expand>
|
||||
<!-- thin -->
|
||||
<ExpandedItem Optional="true">ptr.pointer->data</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer->weak</Item>
|
||||
<ExpandedItem Optional="true">*raw_weak.ptr.pointer</ExpandedItem>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer - 1)->weak</Item>
|
||||
|
||||
<!-- dyn -->
|
||||
<Item Name="[Reference count]" Optional="true">ptr.pointer.pointer->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">ptr.pointer.pointer->weak</Item>
|
||||
<Item Name="[Reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.pointer - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]" Optional="true">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.pointer - 1)->weak</Item>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
||||
<!-- alloc::sync::Weak<[T]> -->
|
||||
<Type Name="alloc::sync::Weak<slice2$<*>,*>">
|
||||
<DisplayString>{{ len={ptr.pointer.length} }}</DisplayString>
|
||||
<DisplayString>{{ len={raw_weak.ptr.pointer.length} }}</DisplayString>
|
||||
<Expand>
|
||||
<Item Name="[Length]" ExcludeView="simple">ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">ptr.pointer.data_ptr->strong</Item>
|
||||
<Item Name="[Weak reference count]">ptr.pointer.data_ptr->weak</Item>
|
||||
<Item Name="[Length]" ExcludeView="simple">raw_weak.ptr.pointer.length</Item>
|
||||
<Item Name="[Reference count]">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.data_ptr - 1)->strong</Item>
|
||||
<Item Name="[Weak reference count]">((alloc::raw_rc::RefCounts *)raw_weak.ptr.pointer.data_ptr - 1)->weak</Item>
|
||||
<ArrayItems>
|
||||
<Size>ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)(((size_t*)ptr.pointer.data_ptr) + 2)</ValuePointer>
|
||||
<Size>raw_weak.ptr.pointer.length</Size>
|
||||
<ValuePointer>($T1*)raw_weak.ptr.pointer.data_ptr</ValuePointer>
|
||||
</ArrayItems>
|
||||
</Expand>
|
||||
</Type>
|
||||
|
@ -1,10 +1,14 @@
|
||||
error: memory leaked: ALLOC (Rust heap, SIZE, ALIGN), allocated here:
|
||||
--> RUSTLIB/alloc/src/rc.rs:LL:CC
|
||||
--> RUSTLIB/alloc/src/raw_rc.rs:LL:CC
|
||||
|
|
||||
LL | Box::leak(Box::new(RcInner { strong: Cell::new(1), weak: Cell::new(1), value }))
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL | let allocation_result = alloc.allocate(rc_layout.allocation_layout);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: BACKTRACE:
|
||||
= note: inside `alloc::raw_rc::allocate_uninit_for_rc::<std::alloc::Global, 1>` at RUSTLIB/alloc/src/raw_rc.rs:LL:CC
|
||||
= note: inside `alloc::raw_rc::RawWeak::<std::cell::RefCell<std::option::Option<Dummy>>, std::alloc::Global>::new_uninit_in::<TAG>` at RUSTLIB/alloc/src/raw_rc.rs:LL:CC
|
||||
= note: inside `alloc::raw_rc::RawWeak::<std::cell::RefCell<std::option::Option<Dummy>>, std::alloc::Global>::new_uninit::<TAG>` at RUSTLIB/alloc/src/raw_rc.rs:LL:CC
|
||||
= note: inside `alloc::raw_rc::RawRc::<std::cell::RefCell<std::option::Option<Dummy>>, std::alloc::Global>::new` at RUSTLIB/alloc/src/raw_rc.rs:LL:CC
|
||||
= note: inside `std::rc::Rc::<std::cell::RefCell<std::option::Option<Dummy>>>::new` at RUSTLIB/alloc/src/rc.rs:LL:CC
|
||||
note: inside `main`
|
||||
--> tests/fail/memleak_rc.rs:LL:CC
|
||||
|
@ -20,8 +20,7 @@ pub fn new_from_array(x: u64) -> Arc<[u64]> {
|
||||
// CHECK-LABEL: @new_uninit
|
||||
#[no_mangle]
|
||||
pub fn new_uninit(x: u64) -> Arc<[u64; 1000]> {
|
||||
// CHECK: call alloc::sync::arcinner_layout_for_value_layout
|
||||
// CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout
|
||||
// CHECK-NOT: call {{<?alloc::raw_rc::RcLayout>?}}::from_value_layout
|
||||
let mut arc = Arc::new_uninit();
|
||||
unsafe { Arc::get_mut_unchecked(&mut arc) }.write([x; 1000]);
|
||||
unsafe { arc.assume_init() }
|
||||
@ -30,8 +29,8 @@ pub fn new_uninit(x: u64) -> Arc<[u64; 1000]> {
|
||||
// CHECK-LABEL: @new_uninit_slice
|
||||
#[no_mangle]
|
||||
pub fn new_uninit_slice(x: u64) -> Arc<[u64]> {
|
||||
// CHECK: call alloc::sync::arcinner_layout_for_value_layout
|
||||
// CHECK-NOT: call alloc::sync::arcinner_layout_for_value_layout
|
||||
// CHECK: call {{<?alloc::raw_rc::RcLayout>?}}::from_value_layout
|
||||
// CHECK-NOT: call {{<?alloc::raw_rc::RcLayout>?}}::from_value_layout
|
||||
let mut arc = Arc::new_uninit_slice(1000);
|
||||
for elem in unsafe { Arc::get_mut_unchecked(&mut arc) } {
|
||||
elem.write(x);
|
||||
|
@ -22,9 +22,11 @@ pub fn box_default_inplace() -> Box<(String, String)> {
|
||||
#[no_mangle]
|
||||
pub fn rc_default_inplace() -> Rc<(String, String)> {
|
||||
// CHECK-NOT: alloca
|
||||
// CHECK: [[RC:%.*]] = {{.*}}call {{.*}}__rust_alloc(
|
||||
// CHECK: [[RC:%.*]] = {{.*}}call {{.*}}__rust_alloc(i[[#BITS:]]
|
||||
// CHECK-NOT: call void @llvm.memcpy
|
||||
// CHECK: ret ptr [[RC]]
|
||||
// CHECK: [[DATA:%.*]] = getelementptr inbounds i8, ptr [[RC]], i[[#BITS]] [[#div(BITS,4)]]
|
||||
// CHECK-NOT: call void @llvm.memcpy
|
||||
// CHECK: ret ptr [[DATA]]
|
||||
Rc::default()
|
||||
}
|
||||
|
||||
@ -32,8 +34,10 @@ pub fn rc_default_inplace() -> Rc<(String, String)> {
|
||||
#[no_mangle]
|
||||
pub fn arc_default_inplace() -> Arc<(String, String)> {
|
||||
// CHECK-NOT: alloca
|
||||
// CHECK: [[ARC:%.*]] = {{.*}}call {{.*}}__rust_alloc(
|
||||
// CHECK: [[RC:%.*]] = {{.*}}call {{.*}}__rust_alloc(i[[#BITS:]]
|
||||
// CHECK-NOT: call void @llvm.memcpy
|
||||
// CHECK: ret ptr [[ARC]]
|
||||
// CHECK: [[DATA:%.*]] = getelementptr inbounds i8, ptr [[RC]], i[[#BITS]] [[#div(BITS,4)]]
|
||||
// CHECK-NOT: call void @llvm.memcpy
|
||||
// CHECK: ret ptr [[DATA]]
|
||||
Arc::default()
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
// lldb-command:v rc
|
||||
// lldb-check:[...] strong=11, weak=1 { value = 111 }
|
||||
// lldb-command:v arc
|
||||
// lldb-check:[...] strong=21, weak=1 { data = 222 }
|
||||
// lldb-check:[...] strong=21, weak=1 { value = 222 }
|
||||
|
||||
// === CDB TESTS ==================================================================================
|
||||
|
||||
@ -27,39 +27,39 @@
|
||||
|
||||
// cdb-command:dx rc,d
|
||||
// cdb-check:rc,d : 111 [Type: alloc::rc::Rc<i32,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 11 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Reference count] : 11 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx weak_rc,d
|
||||
// cdb-check:weak_rc,d : 111 [Type: alloc::rc::Weak<i32,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 11 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Reference count] : 11 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx arc,d
|
||||
// cdb-check:arc,d : 222 [Type: alloc::sync::Arc<i32,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Reference count] : 21 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx weak_arc,d
|
||||
// cdb-check:weak_arc,d : 222 [Type: alloc::sync::Weak<i32,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 21 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Reference count] : 21 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx dyn_rc,d
|
||||
// cdb-check:dyn_rc,d [Type: alloc::rc::Rc<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 31 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Reference count] : 31 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx dyn_rc_weak,d
|
||||
// cdb-check:dyn_rc_weak,d [Type: alloc::rc::Weak<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 31 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Reference count] : 31 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx slice_rc,d
|
||||
// cdb-check:slice_rc,d : { len=3 } [Type: alloc::rc::Rc<slice2$<u32>,alloc::alloc::Global>]
|
||||
// cdb-check: [Length] : 3 [Type: [...]]
|
||||
// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Reference count] : 41 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [0] : 1 [Type: u32]
|
||||
// cdb-check: [1] : 2 [Type: u32]
|
||||
// cdb-check: [2] : 3 [Type: u32]
|
||||
@ -67,27 +67,27 @@
|
||||
// cdb-command:dx slice_rc_weak,d
|
||||
// cdb-check:slice_rc_weak,d : { len=3 } [Type: alloc::rc::Weak<slice2$<u32>,alloc::alloc::Global>]
|
||||
// cdb-check: [Length] : 3 [Type: [...]]
|
||||
// cdb-check: [Reference count] : 41 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell<usize>]
|
||||
// cdb-check: [Reference count] : 41 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [0] : 1 [Type: u32]
|
||||
// cdb-check: [1] : 2 [Type: u32]
|
||||
// cdb-check: [2] : 3 [Type: u32]
|
||||
|
||||
// cdb-command:dx dyn_arc,d
|
||||
// cdb-check:dyn_arc,d [Type: alloc::sync::Arc<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Reference count] : 51 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx dyn_arc_weak,d
|
||||
// cdb-check:dyn_arc_weak,d [Type: alloc::sync::Weak<dyn$<core::fmt::Debug>,alloc::alloc::Global>]
|
||||
// cdb-check: [Reference count] : 51 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Reference count] : 51 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
|
||||
// cdb-command:dx slice_arc,d
|
||||
// cdb-check:slice_arc,d : { len=3 } [Type: alloc::sync::Arc<slice2$<u32>,alloc::alloc::Global>]
|
||||
// cdb-check: [Length] : 3 [Type: [...]]
|
||||
// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Reference count] : 61 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [0] : 4 [Type: u32]
|
||||
// cdb-check: [1] : 5 [Type: u32]
|
||||
// cdb-check: [2] : 6 [Type: u32]
|
||||
@ -95,8 +95,8 @@
|
||||
// cdb-command:dx slice_arc_weak,d
|
||||
// cdb-check:slice_arc_weak,d : { len=3 } [Type: alloc::sync::Weak<slice2$<u32>,alloc::alloc::Global>]
|
||||
// cdb-check: [Length] : 3 [Type: [...]]
|
||||
// cdb-check: [Reference count] : 61 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize]
|
||||
// cdb-check: [Reference count] : 61 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [Weak reference count] : 2 [Type: core::cell::UnsafeCell<usize>]
|
||||
// cdb-check: [0] : 4 [Type: u32]
|
||||
// cdb-check: [1] : 5 [Type: u32]
|
||||
// cdb-check: [2] : 6 [Type: u32]
|
||||
|
@ -19,7 +19,7 @@
|
||||
// gdb-check:$4 = ("Hello", "World")
|
||||
|
||||
// gdb-command:print str_in_rc
|
||||
// gdb-check:$5 = alloc::rc::Rc<&str, alloc::alloc::Global> {ptr: core::ptr::non_null::NonNull<alloc::rc::RcInner<&str>> {pointer: 0x[...]}, phantom: core::marker::PhantomData<alloc::rc::RcInner<&str>>, alloc: alloc::alloc::Global}
|
||||
// gdb-check:$5 = alloc::rc::Rc<&str, alloc::alloc::Global> {raw_rc: alloc::raw_rc::RawRc<&str, alloc::alloc::Global> {weak: alloc::raw_rc::RawWeak<&str, alloc::alloc::Global> {ptr: core::ptr::non_null::NonNull<&str> {pointer: 0x[...]}, alloc: alloc::alloc::Global}, _phantom_data: core::marker::PhantomData<&str>}}
|
||||
|
||||
// === LLDB TESTS ==================================================================================
|
||||
// lldb-command:run
|
||||
@ -38,7 +38,6 @@
|
||||
// lldb-command:v str_in_rc
|
||||
// lldb-check:(alloc::rc::Rc<&str, alloc::alloc::Global>) str_in_rc = strong=1, weak=0 { value = "Hello" { [0] = 'H' [1] = 'e' [2] = 'l' [3] = 'l' [4] = 'o' } }
|
||||
|
||||
|
||||
#![allow(unused_variables)]
|
||||
#![feature(omit_gdb_pretty_printer_section)]
|
||||
#![omit_gdb_pretty_printer_section]
|
||||
|
Loading…
Reference in New Issue
Block a user