Skip to content

Commit e0904cd

Browse files
committed
Add size check inside of the async drop tests
1 parent 5870f1c commit e0904cd

File tree

2 files changed

+105
-65
lines changed

2 files changed

+105
-65
lines changed

Diff for: src/tools/miri/tests/pass/async-drop.rs

+50-29
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ use core::mem::{self, ManuallyDrop};
1111
use core::pin::{pin, Pin};
1212
use core::task::{Context, Poll, Waker};
1313

14-
async fn test_async_drop<T>(x: T) {
14+
async fn test_async_drop<T>(x: T, _size: usize) {
1515
let mut x = mem::MaybeUninit::new(x);
1616
let dtor = pin!(unsafe { async_drop_in_place(x.as_mut_ptr()) });
17+
18+
// FIXME(zetanumbers): This check fully depends on the layout of
19+
// the coroutine state, since async destructor combinators are just
20+
// async functions.
21+
#[cfg(target_pointer_width = "64")]
22+
assert_eq!(
23+
mem::size_of_val(&*dtor),
24+
_size,
25+
"sizes did not match for async destructor of type {}",
26+
core::any::type_name::<T>(),
27+
);
28+
1729
test_idempotency(dtor).await;
1830
}
1931

@@ -34,49 +46,58 @@ fn main() {
3446

3547
let i = 13;
3648
let fut = pin!(async {
37-
test_async_drop(Int(0)).await;
38-
test_async_drop(AsyncInt(0)).await;
39-
test_async_drop([AsyncInt(1), AsyncInt(2)]).await;
40-
test_async_drop((AsyncInt(3), AsyncInt(4))).await;
41-
test_async_drop(5).await;
49+
test_async_drop(Int(0), 16).await;
50+
test_async_drop(AsyncInt(0), 104).await;
51+
test_async_drop([AsyncInt(1), AsyncInt(2)], 152).await;
52+
test_async_drop((AsyncInt(3), AsyncInt(4)), 488).await;
53+
test_async_drop(5, 0).await;
4254
let j = 42;
43-
test_async_drop(&i).await;
44-
test_async_drop(&j).await;
45-
test_async_drop(AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }).await;
46-
test_async_drop(ManuallyDrop::new(AsyncInt(9))).await;
55+
test_async_drop(&i, 0).await;
56+
test_async_drop(&j, 0).await;
57+
test_async_drop(AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }, 1688).await;
58+
test_async_drop(ManuallyDrop::new(AsyncInt(9)), 0).await;
4759

4860
let foo = AsyncInt(10);
49-
test_async_drop(AsyncReference { foo: &foo }).await;
61+
test_async_drop(AsyncReference { foo: &foo }, 104).await;
5062

5163
let foo = AsyncInt(11);
52-
test_async_drop(|| {
53-
black_box(foo);
54-
let foo = AsyncInt(10);
55-
foo
56-
})
64+
test_async_drop(
65+
|| {
66+
black_box(foo);
67+
let foo = AsyncInt(10);
68+
foo
69+
},
70+
120,
71+
)
5772
.await;
5873

59-
test_async_drop(AsyncEnum::A(AsyncInt(12))).await;
60-
test_async_drop(AsyncEnum::B(SyncInt(13))).await;
74+
test_async_drop(AsyncEnum::A(AsyncInt(12)), 792).await;
75+
test_async_drop(AsyncEnum::B(SyncInt(13)), 792).await;
6176

62-
test_async_drop(SyncInt(14)).await;
63-
test_async_drop(SyncThenAsync { i: 15, a: AsyncInt(16), b: SyncInt(17), c: AsyncInt(18) })
64-
.await;
77+
test_async_drop(SyncInt(14), 72).await;
78+
test_async_drop(
79+
SyncThenAsync { i: 15, a: AsyncInt(16), b: SyncInt(17), c: AsyncInt(18) },
80+
3512,
81+
)
82+
.await;
6583

6684
let async_drop_fut = pin!(core::future::async_drop(AsyncInt(19)));
6785
test_idempotency(async_drop_fut).await;
6886

6987
let foo = AsyncInt(20);
70-
test_async_drop(async || {
71-
black_box(foo);
72-
let foo = AsyncInt(19);
73-
// Await point there, but this is async closure so it's fine
74-
black_box(core::future::ready(())).await;
75-
foo
76-
})
88+
test_async_drop(
89+
async || {
90+
black_box(foo);
91+
let foo = AsyncInt(19);
92+
// Await point there, but this is async closure so it's fine
93+
black_box(core::future::ready(())).await;
94+
foo
95+
},
96+
120,
97+
)
7798
.await;
7899

79-
test_async_drop(AsyncUnion { signed: 21 }).await;
100+
test_async_drop(AsyncUnion { signed: 21 }, 32).await;
80101
});
81102
let res = fut.poll(&mut cx);
82103
assert_eq!(res, Poll::Ready(()));

Diff for: tests/ui/async-await/async-drop.rs

+55-36
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,21 @@ use core::mem::{self, ManuallyDrop};
1313
use core::pin::{pin, Pin};
1414
use core::task::{Context, Poll, Waker};
1515

16-
async fn test_async_drop<T>(x: T) {
16+
async fn test_async_drop<T>(x: T, _size: usize) {
1717
let mut x = mem::MaybeUninit::new(x);
1818
let dtor = pin!(unsafe { async_drop_in_place(x.as_mut_ptr()) });
19+
20+
// FIXME(zetanumbers): This check fully depends on the layout of
21+
// the coroutine state, since async destructor combinators are just
22+
// async functions.
23+
#[cfg(target_pointer_width = "64")]
24+
assert_eq!(
25+
mem::size_of_val(&*dtor),
26+
_size,
27+
"sizes did not match for async destructor of type {}",
28+
core::any::type_name::<T>(),
29+
);
30+
1931
test_idempotency(dtor).await;
2032
}
2133

@@ -36,51 +48,58 @@ fn main() {
3648

3749
let i = 13;
3850
let fut = pin!(async {
39-
test_async_drop(Int(0)).await;
40-
test_async_drop(AsyncInt(0)).await;
41-
test_async_drop([AsyncInt(1), AsyncInt(2)]).await;
42-
test_async_drop((AsyncInt(3), AsyncInt(4))).await;
43-
test_async_drop(5).await;
51+
test_async_drop(Int(0), 16).await;
52+
test_async_drop(AsyncInt(0), 104).await;
53+
test_async_drop([AsyncInt(1), AsyncInt(2)], 152).await;
54+
test_async_drop((AsyncInt(3), AsyncInt(4)), 488).await;
55+
test_async_drop(5, 0).await;
4456
let j = 42;
45-
test_async_drop(&i).await;
46-
test_async_drop(&j).await;
47-
test_async_drop(AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }).await;
48-
test_async_drop(ManuallyDrop::new(AsyncInt(9))).await;
57+
test_async_drop(&i, 0).await;
58+
test_async_drop(&j, 0).await;
59+
test_async_drop(AsyncStruct { b: AsyncInt(8), a: AsyncInt(7), i: 6 }, 1688).await;
60+
test_async_drop(ManuallyDrop::new(AsyncInt(9)), 0).await;
4961

5062
let foo = AsyncInt(10);
51-
test_async_drop(AsyncReference { foo: &foo }).await;
63+
test_async_drop(AsyncReference { foo: &foo }, 104).await;
5264

5365
let foo = AsyncInt(11);
54-
test_async_drop(|| {
55-
black_box(foo);
56-
let foo = AsyncInt(10);
57-
foo
58-
}).await;
59-
60-
test_async_drop(AsyncEnum::A(AsyncInt(12))).await;
61-
test_async_drop(AsyncEnum::B(SyncInt(13))).await;
62-
63-
test_async_drop(SyncInt(14)).await;
64-
test_async_drop(SyncThenAsync {
65-
i: 15,
66-
a: AsyncInt(16),
67-
b: SyncInt(17),
68-
c: AsyncInt(18),
69-
}).await;
66+
test_async_drop(
67+
|| {
68+
black_box(foo);
69+
let foo = AsyncInt(10);
70+
foo
71+
},
72+
120,
73+
)
74+
.await;
75+
76+
test_async_drop(AsyncEnum::A(AsyncInt(12)), 792).await;
77+
test_async_drop(AsyncEnum::B(SyncInt(13)), 792).await;
78+
79+
test_async_drop(SyncInt(14), 72).await;
80+
test_async_drop(
81+
SyncThenAsync { i: 15, a: AsyncInt(16), b: SyncInt(17), c: AsyncInt(18) },
82+
3512,
83+
)
84+
.await;
7085

7186
let async_drop_fut = pin!(core::future::async_drop(AsyncInt(19)));
7287
test_idempotency(async_drop_fut).await;
7388

7489
let foo = AsyncInt(20);
75-
test_async_drop(async || {
76-
black_box(foo);
77-
let foo = AsyncInt(19);
78-
// Await point there, but this is async closure so it's fine
79-
black_box(core::future::ready(())).await;
80-
foo
81-
}).await;
82-
83-
test_async_drop(AsyncUnion { signed: 21 }).await;
90+
test_async_drop(
91+
async || {
92+
black_box(foo);
93+
let foo = AsyncInt(19);
94+
// Await point there, but this is async closure so it's fine
95+
black_box(core::future::ready(())).await;
96+
foo
97+
},
98+
120,
99+
)
100+
.await;
101+
102+
test_async_drop(AsyncUnion { signed: 21 }, 32).await;
84103
});
85104
let res = fut.poll(&mut cx);
86105
assert_eq!(res, Poll::Ready(()));

0 commit comments

Comments
 (0)